Skip to content

Commit

Permalink
refactor: use canonicalize to replace Command::current_dir method
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu committed Sep 23, 2024
1 parent 9bb2af2 commit 96d7fa4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/ops/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ fn do_call(
return Ok(true);
}
let mut iter = command.iter();
let cmd_name = iter.next().unwrap();
let origin_cmd_name: &String = iter.next().unwrap();

let mut cmd = Command::new(cmd_name);
// convert to absolute path if path is existed as first and avoid to use Command::current_dir
let cmd_name = path.map_or_else(
|| origin_cmd_name.clone(),
|p| {
dunce::canonicalize(p.join(origin_cmd_name))
.map(|path| path.to_string_lossy().into_owned())
.unwrap_or_else(|_| p.join(origin_cmd_name).to_string_lossy().into_owned())
},
);

Check failure

Code scanning / clippy

use of a disallowed method std::option::Option::map_or_else Error

use of a disallowed method std::option::Option::map\_or\_else

Check failure

Code scanning / clippy

use of a disallowed method std::option::Option::map_or_else Error

use of a disallowed method std::option::Option::map\_or\_else

if let Some(p) = path {
cmd.current_dir(p);
}
let mut cmd = Command::new(&cmd_name);

if let Some(e) = envs {
cmd.envs(e.iter());
Expand Down

0 comments on commit 96d7fa4

Please sign in to comment.