Closed sweep-ai[bot] closed 9 months 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?
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
}
Done.
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
Done.
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
Done.
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
Done.
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 thegit pull
command is executed in thedownload_plugin_from_github
function influere-plugin/src/downloader.rs
. Instead of concatenating thecd_cmd
andgit pull
commands, thecurrent_dir
method of theCommand
struct is used to change the working directory before executing thegit pull
command. TheCommand::new("bash")
calls were replaced withCommand::new("git")
and the arguments were adjusted accordingly.The second issue is a panic error on macOS related to the
unwrap()
function call influere-plugin/src/util.rs
. This was fixed by replacing theunwrap()
function call on thecache_dir()
function with the?
operator to propagate the error up the call stack.Summary of Changes
download_plugin_from_github
function influere-plugin/src/downloader.rs
to fix thegit pull
command issue.unwrap()
function call influere-plugin/src/util.rs
with the?
operator to fix the panic error on macOS.Fixes #69.
π Latest improvements to Sweep:
rope
library to refactor Python! Check out Large Language Models are Bad at Refactoring Code. To have Sweep refactor your code, trysweep: Refactor <your_file>.py to be more modular
!π‘ To get Sweep to edit this pull request, you can: