Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/uu/ln/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ ln-error-missing-destination = missing destination file operand after {$operand}
ln-error-extra-operand = extra operand {$operand}
Try '{$program} --help' for more information.
ln-error-could-not-update = Could not update {$target}: {$error}
ln-error-cannot-stat = cannot stat {$path}: No such file or directory
ln-error-will-not-overwrite = will not overwrite just-created '{$target}' with '{$source}'
ln-prompt-replace = replace {$file}?
ln-cannot-backup = cannot backup {$file}
Expand Down
1 change: 0 additions & 1 deletion src/uu/ln/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ln-error-missing-destination = opérande de fichier de destination manquant apr
ln-error-extra-operand = opérande supplémentaire {$operand}
Essayez « {$program} --help » pour plus d'informations.
ln-error-could-not-update = Impossible de mettre à jour {$target} : {$error}
ln-error-cannot-stat = impossible d'analyser {$path} : Aucun fichier ou répertoire de ce nom
ln-error-will-not-overwrite = ne remplacera pas le fichier « {$target} » qui vient d'être créé par « {$source} »
ln-prompt-replace = remplacer {$file} ?
ln-cannot-backup = impossible de sauvegarder {$file}
Expand Down
46 changes: 17 additions & 29 deletions src/uu/ln/src/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.map(PathBuf::from)
.collect();

let symbolic = matches.get_flag(options::SYMBOLIC);

let overwrite_mode = if matches.get_flag(options::FORCE) {
OverwriteMode::Force
} else if matches.get_flag(options::INTERACTIVE) {
Expand All @@ -114,15 +112,13 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let backup_mode = backup_control::determine_backup_mode(&matches)?;
let backup_suffix = backup_control::determine_backup_suffix(&matches);

// When we have "-L" or "-L -P", false otherwise
let logical = matches.get_flag(options::LOGICAL);

let settings = Settings {
overwrite: overwrite_mode,
backup: backup_mode,
suffix: OsString::from(backup_suffix),
symbolic,
logical,
symbolic: matches.get_flag(options::SYMBOLIC),
// When we have "-L" or "-L -P", false otherwise
logical: matches.get_flag(options::LOGICAL),
relative: matches.get_flag(options::RELATIVE),
target_dir: matches
.get_one::<OsString>(options::TARGET_DIRECTORY)
Expand All @@ -132,7 +128,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
verbose: matches.get_flag(options::VERBOSE),
};

exec(&paths[..], &settings)
exec(&paths, &settings)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Was a bit confused when trying to understand what the [..] was doing when I was reading this, turns out its redundant

}

pub fn uu_app() -> Command {
Expand Down Expand Up @@ -295,8 +291,10 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
&& matches!(settings.overwrite, OverwriteMode::Force)
&& target_dir.is_symlink()
{
// In that case, we don't want to do link resolution
// We need to clean the target
// We don't want to do link resolution, we need to clean the target.
// Unreachable on Unix: target_dir is a symlink to a directory here,
// so is_file() is always false.
#[cfg(windows)]
if target_dir.is_file() {
if let Err(e) = fs::remove_file(target_dir) {
show_error!(
Expand All @@ -319,25 +317,15 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
}
target_dir.to_path_buf()
} else {
match srcpath.as_os_str().to_str() {
Some(name) => {
match Path::new(name).file_name() {
Some(basename) => target_dir.join(basename),
// This can be None only for "." or "..". Trying
// to create a link with such name will fail with
// EEXIST, which agrees with the behavior of GNU
// coreutils.
None => target_dir.join(name),
}
}
None => {
show_error!(
"{}",
translate!("ln-error-cannot-stat", "path" => srcpath.quote())
);
all_successful = false;
continue;
}
// Use OsStr directly to handle non-UTF8 paths correctly
let name = srcpath.as_os_str();
match srcpath.file_name() {
Some(basename) => target_dir.join(basename),
// This can be None only for "." or "..". Trying
// to create a link with such name will fail with
// EEXIST, which agrees with the behavior of GNU
// coreutils.
None => target_dir.join(name),
}
};

Expand Down
Loading
Loading