Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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: 1 addition & 0 deletions src/uu/readlink/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ readlink-help-zero = separate output with NUL rather than newline
# Error messages
readlink-error-missing-operand = missing operand
readlink-error-ignoring-no-newline = ignoring --no-newline with multiple arguments
readlink-error-invalid-argument = {$path}: Invalid argument
1 change: 1 addition & 0 deletions src/uu/readlink/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ readlink-help-zero = séparer la sortie avec NUL plutôt qu'une nouvelle ligne
# Messages d'erreur
readlink-error-missing-operand = opérande manquant
readlink-error-ignoring-no-newline = ignorer --no-newline avec plusieurs arguments
readlink-error-invalid-argument = {$path} : argument non valide
20 changes: 12 additions & 8 deletions src/uu/readlink/src/readlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use std::ffi::OsString;
use std::fs;
use std::io::{Write, stdout};
use std::path::{Path, PathBuf};
use uucore::error::{FromIo, UResult, USimpleError, UUsageError};
use uucore::error::{FromIo, UResult, UUsageError};
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
use uucore::libc::EINVAL;
use uucore::line_ending::LineEnding;
use uucore::translate;
use uucore::{format_usage, show_error};
Expand Down Expand Up @@ -88,15 +89,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
show(&path, line_ending).map_err_context(String::new)?;
}
Err(err) => {
return if verbose {
Err(USimpleError::new(
1,
err.map_err_context(move || p.to_string_lossy().to_string())
.to_string(),
))
if silent && !verbose {
return Err(1.into());
}

let path = p.to_string_lossy().into_owned();
let message = if err.raw_os_error() == Some(EINVAL) {
translate!("readlink-error-invalid-argument", "path" => path.clone())
} else {
Err(1.into())
err.map_err_context(|| path.clone()).to_string()
};
show_error!("{message}");
return Err(1.into());
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_readlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ fn test_symlink_to_itself_verbose() {
.stderr_contains("Too many levels of symbolic links");
}

#[test]
#[cfg(not(windows))]
fn test_posixly_correct_regular_file() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("regfile");
scene
.ucmd()
.env("POSIXLY_CORRECT", "1")
.arg("regfile")
.fails_with_code(1)
.stderr_contains("Invalid argument")
.no_stdout();
}

#[test]
fn test_trailing_slash_regular_file() {
let scene = TestScenario::new(util_name!());
Expand Down
Loading