1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-17 12:16:17 +00:00

refactor/ln ~ fix cargo clippy complaint (clippy::needless_borrow)

This commit is contained in:
Roy Ivy III 2021-06-06 11:46:52 -05:00
parent 4a09c72fe7
commit e8e28f1508

View file

@ -260,17 +260,17 @@ fn exec(files: &[PathBuf], settings: &Settings) -> i32 {
// Handle cases where we create links in a directory first. // Handle cases where we create links in a directory first.
if let Some(ref name) = settings.target_dir { if let Some(ref name) = settings.target_dir {
// 4th form: a directory is specified by -t. // 4th form: a directory is specified by -t.
return link_files_in_dir(files, &PathBuf::from(name), &settings); return link_files_in_dir(files, &PathBuf::from(name), settings);
} }
if !settings.no_target_dir { if !settings.no_target_dir {
if files.len() == 1 { if files.len() == 1 {
// 2nd form: the target directory is the current directory. // 2nd form: the target directory is the current directory.
return link_files_in_dir(files, &PathBuf::from("."), &settings); return link_files_in_dir(files, &PathBuf::from("."), settings);
} }
let last_file = &PathBuf::from(files.last().unwrap()); let last_file = &PathBuf::from(files.last().unwrap());
if files.len() > 2 || last_file.is_dir() { if files.len() > 2 || last_file.is_dir() {
// 3rd form: create links in the last argument. // 3rd form: create links in the last argument.
return link_files_in_dir(&files[0..files.len() - 1], last_file, &settings); return link_files_in_dir(&files[0..files.len() - 1], last_file, settings);
} }
} }
@ -392,7 +392,7 @@ fn relative_path<'a>(src: &Path, dst: &Path) -> Result<Cow<'a, Path>> {
fn link(src: &Path, dst: &Path, settings: &Settings) -> Result<()> { fn link(src: &Path, dst: &Path, settings: &Settings) -> Result<()> {
let mut backup_path = None; let mut backup_path = None;
let source: Cow<'_, Path> = if settings.relative { let source: Cow<'_, Path> = if settings.relative {
relative_path(&src, dst)? relative_path(src, dst)?
} else { } else {
src.into() src.into()
}; };