SkuldNorniern / fluere

Fluere is a powerful and versatile tool designed for network monitoring and analysis. It is capable of capturing network packets in pcap format and converting them into NetFlow data, providing a comprehensive view of network traffic. It also Provides Terminal User Interface.
Apache License 2.0
37 stars 3 forks source link

Fix git pull issue and unwrap error #80

Closed sweep-ai[bot] closed 9 months ago

sweep-ai[bot] commented 1 year ago

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

Fixes #69.


πŸŽ‰ Latest improvements to Sweep:


πŸ’‘ To get Sweep to edit this pull request, you can:

sweep-ai[bot] commented 1 year ago

Sandbox Executions

sweep-ai[bot] commented 1 year ago

Apply Sweep Rules to your PR?

coderabbitai[bot] commented 1 year ago

[!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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

Tips ### Chat with CodeRabbit Bot (`@coderabbitai`) - You can directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://coderabbit.ai/integrations/coderabbit-overrides.v2.json). - 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](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback.
SkuldNorniern commented 1 year ago

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
}
sweep-ai[bot] commented 1 year ago

πŸš€ Wrote Changes

Done.

SkuldNorniern commented 1 year ago
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
sweep-ai[bot] commented 1 year ago

πŸš€ Wrote Changes

Done.

SkuldNorniern commented 1 year ago
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
sweep-ai[bot] commented 1 year ago

πŸš€ Wrote Changes

Done.

SkuldNorniern commented 1 year ago

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

sweep-ai[bot] commented 1 year ago

πŸš€ Wrote Changes

Done.