Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git pull issue and unwrap error #80

Closed
wants to merge 18 commits into from

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented Nov 8, 2023

PR Feedback: 👎

Description

This PR addresses two issues. The first issue is the git pull command not working when updating the downloaded plugin. This was fixed by modifying the way the git pull command is executed in the download_plugin_from_github function in fluere-plugin/src/downloader.rs. Instead of concatenating the cd_cmd and git pull commands, the current_dir method of the Command struct is used to change the working directory before executing the git pull command. The Command::new("bash") calls were replaced with Command::new("git") and the arguments were adjusted accordingly.

The second issue is a panic error on macOS related to the unwrap() function call in fluere-plugin/src/util.rs. This was fixed by replacing the unwrap() function call on the cache_dir() function with the ? operator to propagate the error up the call stack.

Summary of Changes

  • Modified the download_plugin_from_github function in fluere-plugin/src/downloader.rs to fix the git pull command issue.
  • Replaced the unwrap() function call in fluere-plugin/src/util.rs with the ? operator to fix the panic error on macOS.

Fixes #69.


🎉 Latest improvements to Sweep:


💡 To get Sweep to edit this pull request, you can:

  • Comment below, and Sweep can edit the entire PR
  • Comment on a file, Sweep will only modify the commented file
  • Edit the original issue to get Sweep to recreate the PR from scratch

sweep-ai bot added 2 commits November 8, 2023 05:07

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor Author

sweep-ai bot commented Nov 8, 2023

Sandbox Executions

Copy link
Contributor Author

sweep-ai bot commented Nov 8, 2023

Apply Sweep Rules to your PR?

@sweep-ai sweep-ai bot added the sweep Assigns Sweep to an issue or pull request. label Nov 8, 2023
Copy link

coderabbitai bot commented Nov 8, 2023

Important

Auto Review Skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid.
    • @coderabbitai read the files in the src/scheduler package and generate README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@SkuldNorniern
Copy link
Owner

can you change the util.rs code based on this code?


fn home_config_path() -> PathBuf {
    // Check for the SUDO_USER environment variable
    let sudo_user = env::var("SUDO_USER");

    let path_base = match sudo_user {
        Ok(user) => {
            // on macOS just return the config_dir()
            if env::consts::OS == "macos" {
                config_dir().expect("Could not determine the home directory")
            } else {
                // If SUDO_USER is set, construct the path using the user's home directory
                let user_home = format!("/home/{}", user);
                Path::new(&user_home).join(".config")
            }
        }
        Err(_) => {
            // If not running under sudo, just use the config_dir function as before
            config_dir().expect("Could not determine the home directory")
        }
    };
    let path_config = path_base.join("fluere");
    path_config
}

Copy link
Contributor Author

sweep-ai bot commented Nov 8, 2023

🚀 Wrote Changes

Done.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
}
Err(_) => {
// If not running under sudo, just use the config_dir function as before
// If not running under sudo, just use the cache_dir function as before
cache_dir()?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error[E0277]: the ? operator can only be used in a function that returns Result or Option (or another type that implements FromResidual)
--> fluere-plugin/src/util.rs:24:24
|
7 | pub fn home_cache_path() -> PathBuf {
| ----------------------------------- this function should return Result or Option to accept ?
...
24 | cache_dir()?
| ^ cannot use the ? operator in a function that returns PathBuf
|
= help: the trait FromResidual<Option<Infallible>> is not implemented for PathBuf

For more information about this error, try rustc --explain E0277.
error: could not compile fluere_plugin (lib) due to previous error

Copy link
Contributor Author

@sweep-ai sweep-ai bot Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Wrote Changes

Done.

sweep-ai bot and others added 2 commits November 8, 2023 05:30

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@SkuldNorniern
Copy link
Owner

error[E0599]: no method named `join` found for enum `Result` in the current scope
    --> fluere-plugin/src/lib.rs:106:62
     |
106  | ...                   let path = home_cache_path().join(name.split('/').last().unwrap());
     |                                                    ^^^^ method not found in `Result<PathBuf, Error>`
     |
note: the method `join` exists on the type `PathBuf`
    --> /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/path.rs:2550:5
     |
2550 |     pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `PathBuf` value, propagating a `Result::Err` value to the caller
     |
106  |                                 let path = home_cache_path()?.join(name.split('/').last().unwrap());
     |                                                             +

error[E0599]: no method named `exists` found for enum `Result` in the current scope
    --> fluere-plugin/src/downloader.rs:7:14
     |
7    |     if !path.exists() {
     |              ^^^^^^ method not found in `Result<PathBuf, Error>`
     |
note: the method `exists` exists on the type `PathBuf`
    --> /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/path.rs:2843:5
     |
2843 |     pub fn exists(&self) -> bool {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `PathBuf` value, propagating a `Result::Err` value to the caller
     |
7    |     if !path?.exists() {
     |             +

error[E0599]: the method `clone` exists for enum `Result<PathBuf, Error>`, but its trait bounds were not satisfied
   --> fluere-plugin/src/downloader.rs:8:38
    |
8   |         std::fs::create_dir_all(path.clone())?;
    |                                      ^^^^^ method cannot be called on `Result<PathBuf, Error>` due to unsatisfied trait bounds
    |
   ::: /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:502:1
    |
502 | pub enum Result<T, E> {
    | --------------------- doesn't satisfy `Result<PathBuf, std::io::Error>: Clone`
    |
   ::: /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/io/error.rs:67:1
    |
67  | pub struct Error {
    | ---------------- doesn't satisfy `std::io::Error: Clone`
    |
    = note: the following trait bounds were not satisfied:
            `std::io::Error: Clone`
            which is required by `Result<PathBuf, std::io::Error>: Clone`
note: the method `clone` exists on the type `PathBuf`
   --> /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/clone.rs:120:5
    |
120 |     fn clone(&self) -> Self;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `PathBuf` value, propagating a `Result::Err` value to the caller
    |
8   |         std::fs::create_dir_all(path?.clone())?;
    |                                     +

error[E0599]: no method named `join` found for enum `Result` in the current scope
    --> fluere-plugin/src/downloader.rs:10:26
     |
10   |     let repo_path = path.join(repo_name.split('/').last().unwrap());
     |                          ^^^^ method not found in `Result<PathBuf, Error>`
     |
note: the method `join` exists on the type `PathBuf`
    --> /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/path.rs:2550:5
     |
2550 |     pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: use the `?` operator to extract the `PathBuf` value, propagating a `Result::Err` value to the caller
     |
10   |     let repo_path = path?.join(repo_name.split('/').last().unwrap());
     |                         +

error[E0277]: the trait bound `Result<PathBuf, std::io::Error>: AsRef<Path>` is not satisfied
   --> fluere-plugin/src/downloader.rs:19:27
    |
19  |             .current_dir(&path)
    |              -----------  ^^^^ the trait `AsRef<Path>` is not implemented for `Result<PathBuf, std::io::Error>`
    |              |
    |              required by a bound introduced by this call
    |
    = note: required for `&Result<PathBuf, std::io::Error>` to implement `AsRef<Path>`
note: required by a bound in `std::process::Command::current_dir`
   --> /Users/skuldnorniern/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/process.rs:830:27
    |
830 |     pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command {
    |                           ^^^^^^^^^^^ required by this bound in `Command::current_dir`

error[E0308]: `match` arms have incompatible types
  --> fluere-plugin/src/util.rs:24:13
   |
11 |       let path_base = match sudo_user {
   |                       --------------- `match` arms have incompatible types
...
14 | /             if env::consts::OS == "macos" {
15 | |                 cache_dir().expect("Could not determine the home directory")
16 | |             } else {
17 | |                 // If SUDO_USER is set, construct the path using the user's home directory
18 | |                 let user_home = format!("/home/{}", user);
19 | |                 Path::new(&user_home).join(".cache")
20 | |             }
   | |_____________- this is found to be of type `PathBuf`
...
24 | /             cache_dir().ok_or(std::io::Error::new(
25 | |                 std::io::ErrorKind::NotFound,
26 | |                 "Could not determine the cache directory",
27 | |             ))
   | |______________^ expected `PathBuf`, found `Result<PathBuf, Error>`
   |
   = note: expected struct `PathBuf`
                found enum `Result<PathBuf, std::io::Error>`

Some errors have detailed explanations: E0277, E0308, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `fluere_plugin` (lib) due to 6 previous errors

Copy link
Contributor Author

sweep-ai bot commented Nov 8, 2023

🚀 Wrote Changes

Done.

sweep-ai bot added 2 commits November 8, 2023 05:39

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@SkuldNorniern
Copy link
Owner

error[E0599]: no method named `join` found for enum `Result` in the current scope

   --> fluere-plugin/src/lib.rs:106:62

    |

106 | ...                   let path = home_cache_path().join(name.split('/').last().unwrap());

    |                                                    ^^^^ method not found in `Result<PathBuf, Error>`

    |

note: the method `join` exists on the type `PathBuf`

   --> /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/path.rs:2554:5

help: use the `?` operator to extract the `PathBuf` value, propagating a `Result::Err` value to the caller

    |

106 |                                 let path = home_cache_path()?.join(name.split('/').last().unwrap());

    |                                                             +


error[E0277]: the `?` operator can only be applied to values that implement `Try`

  --> fluere-plugin/src/downloader.rs:10:21

   |

10 |     let repo_path = path?.join(repo_name.split('/').last().unwrap());

   |                     ^^^^^ the `?` operator cannot be applied to type `PathBuf`

   |

   = help: the trait `Try` is not implemented for `PathBuf`


error[E0277]: the `?` operator can only be applied to values that implement `Try`

  --> fluere-plugin/src/downloader.rs:19:27

   |

19 |             .current_dir(&path?)

   |                           ^^^^^ the `?` operator cannot be applied to type `PathBuf`

   |

   = help: the trait `Try` is not implemented for `PathBuf`


error[E0599]: no method named `join` found for enum `Result` in the current scope

  --> fluere-plugin/src/util.rs:30:32

   |

30 |     let path_cache = path_base.join("fluere");

   |                                ^^^^ method not found in `Result<PathBuf, Error>`

   |

note: the method `join` exists on the type `PathBuf`

  --> /rustc/eb26296b556cef10fb713a38f3d16b9886080f26/library/std/src/path.rs:2554:5

help: use the `?` operator to extract the `PathBuf` value, propagating a `Result::Err` value to the caller

   |

30 |     let path_cache = path_base?.join("fluere");

   |                               +


Some errors have detailed explanations: E0277, E0599.

For more information about an error, try `rustc --explain E0277`.

error: could not compile `fluere_plugin` (lib) due to 4 previous errors

Copy link
Contributor Author

sweep-ai bot commented Nov 8, 2023

🚀 Wrote Changes

Done.

sweep-ai bot and others added 4 commits November 8, 2023 05:50

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@SkuldNorniern
Copy link
Owner

git pull was not able to pull the updated changes,
and it is seems to caused by the dubious ownership, force it or use a another crate to handle git, or any other way

Copy link
Contributor Author

sweep-ai bot commented Nov 8, 2023

🚀 Wrote Changes

Done.

sweep-ai bot and others added 5 commits November 8, 2023 08:01

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
sweep-ai bot and others added 2 commits January 2, 2024 08:32

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@SkuldNorniern SkuldNorniern deleted the sweep/git-pull-and-unwrap-error branch February 2, 2024 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Assigns Sweep to an issue or pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: git pull on downloaded plugin does not working
2 participants