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
16 changes: 16 additions & 0 deletions src/uu/pathchk/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
pathchk-about = Check whether file names are valid or portable
pathchk-usage = pathchk [OPTION]... NAME...

# Help messages
pathchk-help-posix = check for most POSIX systems
pathchk-help-posix-special = check for empty names and leading "-"
pathchk-help-portability = check for all POSIX systems (equivalent to -p -P)

# Error messages
pathchk-error-missing-operand = missing operand
pathchk-error-empty-file-name = empty file name
pathchk-error-posix-path-length-exceeded = limit { $limit } exceeded by length { $length } of file name { $path }
pathchk-error-posix-name-length-exceeded = limit { $limit } exceeded by length { $length } of file name component { $component }
pathchk-error-leading-hyphen = leading hyphen in file name component { $component }
pathchk-error-path-length-exceeded = limit { $limit } exceeded by length { $length } of file name { $path }
pathchk-error-name-length-exceeded = limit { $limit } exceeded by length { $length } of file name component { $component }
pathchk-error-empty-path-not-found = pathchk: '': No such file or directory
pathchk-error-nonportable-character = nonportable character '{ $character }' in file name component { $component }
18 changes: 18 additions & 0 deletions src/uu/pathchk/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pathchk-about = Vérifier si les noms de fichiers sont valides ou portables
pathchk-usage = pathchk [OPTION]... NOM...

# Messages d'aide
pathchk-help-posix = vérifier pour la plupart des systèmes POSIX
pathchk-help-posix-special = vérifier les noms vides et les "-" en début
pathchk-help-portability = vérifier pour tous les systèmes POSIX (équivalent à -p -P)

# Messages d'erreur
pathchk-error-missing-operand = opérande manquant
pathchk-error-empty-file-name = nom de fichier vide
pathchk-error-posix-path-length-exceeded = limite { $limit } dépassée par la longueur { $length } du nom de fichier { $path }
pathchk-error-posix-name-length-exceeded = limite { $limit } dépassée par la longueur { $length } du composant de nom de fichier { $component }
pathchk-error-leading-hyphen = tiret en début dans le composant de nom de fichier { $component }
pathchk-error-path-length-exceeded = limite { $limit } dépassée par la longueur { $length } du nom de fichier { $path }
pathchk-error-name-length-exceeded = limite { $limit } dépassée par la longueur { $length } du composant de nom de fichier { $component }
pathchk-error-empty-path-not-found = pathchk: '' : Aucun fichier ou répertoire de ce type
pathchk-error-nonportable-character = caractère non portable '{ $character }' dans le composant de nom de fichier { $component }
94 changes: 73 additions & 21 deletions src/uu/pathchk/src/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

// spell-checker:ignore (ToDO) lstat
use clap::{Arg, ArgAction, Command};
use std::collections::HashMap;
use std::fs;
use std::io::{ErrorKind, Write};
use uucore::display::Quotable;
use uucore::error::{UResult, UUsageError, set_exit_code};
use uucore::format_usage;
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};

// operating mode
enum Mode {
Expand Down Expand Up @@ -54,7 +55,10 @@
// take necessary actions
let paths = matches.get_many::<String>(options::PATH);
if paths.is_none() {
return Err(UUsageError::new(1, "missing operand"));
return Err(UUsageError::new(
1,
get_message("pathchk-error-missing-operand"),
));
}

// free strings are path operands
Expand Down Expand Up @@ -84,19 +88,19 @@
.arg(
Arg::new(options::POSIX)
.short('p')
.help("check for most POSIX systems")
.help(get_message("pathchk-help-posix"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::POSIX_SPECIAL)
.short('P')
.help(r#"check for empty names and leading "-""#)
.help(get_message("pathchk-help-posix-special"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::PORTABILITY)
.long(options::PORTABILITY)
.help("check for all POSIX systems (equivalent to -p -P)")
.help(get_message("pathchk-help-portability"))
.action(ArgAction::SetTrue),
)
.arg(
Expand Down Expand Up @@ -125,11 +129,23 @@
if total_len > POSIX_PATH_MAX {
writeln!(
std::io::stderr(),
"limit {POSIX_PATH_MAX} exceeded by length {total_len} of file name {joined_path}"
"{}",
get_message_with_args(
"pathchk-error-posix-path-length-exceeded",
HashMap::from([
("limit".to_string(), POSIX_PATH_MAX.to_string()),
("length".to_string(), total_len.to_string()),
("path".to_string(), joined_path),
])
)
);
return false;
} else if total_len == 0 {
writeln!(std::io::stderr(), "empty file name");
writeln!(
std::io::stderr(),
"{}",
get_message("pathchk-error-empty-file-name")
);
return false;
}
// components: character portability and length
Expand All @@ -138,8 +154,15 @@
if component_len > POSIX_NAME_MAX {
writeln!(
std::io::stderr(),
"limit {POSIX_NAME_MAX} exceeded by length {component_len} of file name component {}",
p.quote()
"{}",
get_message_with_args(
"pathchk-error-posix-name-length-exceeded",
HashMap::from([
("limit".to_string(), POSIX_NAME_MAX.to_string()),
("length".to_string(), component_len.to_string()),
("component".to_string(), p.quote().to_string()),
])

Check warning on line 164 in src/uu/pathchk/src/pathchk.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/pathchk/src/pathchk.rs#L157-L164

Added lines #L157 - L164 were not covered by tests
)
);
return false;
}
Expand All @@ -158,15 +181,22 @@
if p.starts_with('-') {
writeln!(
std::io::stderr(),
"leading hyphen in file name component {}",
p.quote()
"{}",
get_message_with_args(
"pathchk-error-leading-hyphen",
HashMap::from([("component".to_string(), p.quote().to_string())])
)
);
return false;
}
}
// path length
if path.join("/").is_empty() {
writeln!(std::io::stderr(), "empty file name");
writeln!(
std::io::stderr(),
"{}",
get_message("pathchk-error-empty-file-name")

Check warning on line 198 in src/uu/pathchk/src/pathchk.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/pathchk/src/pathchk.rs#L195-L198

Added lines #L195 - L198 were not covered by tests
);
return false;
}
true
Expand All @@ -180,9 +210,15 @@
if total_len > libc::PATH_MAX as usize {
writeln!(
std::io::stderr(),
"limit {} exceeded by length {total_len} of file name {}",
libc::PATH_MAX,
joined_path.quote()
"{}",
get_message_with_args(
"pathchk-error-path-length-exceeded",
HashMap::from([
("limit".to_string(), libc::PATH_MAX.to_string()),
("length".to_string(), total_len.to_string()),
("path".to_string(), joined_path.quote().to_string()),
])
)
);
return false;
}
Expand All @@ -192,7 +228,11 @@
// but some non-POSIX hosts do (as an alias for "."),
// so allow "" if `symlink_metadata` (corresponds to `lstat`) does.
if fs::symlink_metadata(&joined_path).is_err() {
writeln!(std::io::stderr(), "pathchk: '': No such file or directory");
writeln!(
std::io::stderr(),
"{}",
get_message("pathchk-error-empty-path-not-found")
);
return false;
}
}
Expand All @@ -203,9 +243,15 @@
if component_len > libc::FILENAME_MAX as usize {
writeln!(
std::io::stderr(),
"limit {} exceeded by length {component_len} of file name component {}",
libc::FILENAME_MAX,
p.quote()
"{}",
get_message_with_args(
"pathchk-error-name-length-exceeded",
HashMap::from([
("limit".to_string(), libc::FILENAME_MAX.to_string()),
("length".to_string(), component_len.to_string()),
("component".to_string(), p.quote().to_string()),
])

Check warning on line 253 in src/uu/pathchk/src/pathchk.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/pathchk/src/pathchk.rs#L246-L253

Added lines #L246 - L253 were not covered by tests
)
);
return false;
}
Expand Down Expand Up @@ -238,8 +284,14 @@
let invalid = path_segment[i..].chars().next().unwrap();
writeln!(
std::io::stderr(),
"nonportable character '{invalid}' in file name component {}",
path_segment.quote()
"{}",
get_message_with_args(
"pathchk-error-nonportable-character",
HashMap::from([
("character".to_string(), invalid.to_string()),
("component".to_string(), path_segment.quote().to_string()),
])
)
);
return false;
}
Expand Down
Loading