diff --git a/src/uu/chroot/locales/en-US.ftl b/src/uu/chroot/locales/en-US.ftl index 86687fea8..992c4b98a 100644 --- a/src/uu/chroot/locales/en-US.ftl +++ b/src/uu/chroot/locales/en-US.ftl @@ -1,2 +1,24 @@ chroot-about = Run COMMAND with root directory set to NEWROOT. chroot-usage = chroot [OPTION]... NEWROOT [COMMAND [ARG]...] + +# Help messages +chroot-help-groups = Comma-separated list of groups to switch to +chroot-help-userspec = Colon-separated user and group to switch to. +chroot-help-skip-chdir = Use this option to not change the working directory to / after changing the root directory to newroot, i.e., inside the chroot. + +# Error messages +chroot-error-skip-chdir-only-permitted = option --skip-chdir only permitted if NEWROOT is old '/' +chroot-error-cannot-enter = cannot chroot to { $dir }: { $err } +chroot-error-command-failed = failed to run command { $cmd }: { $err } +chroot-error-command-not-found = failed to run command { $cmd }: { $err } +chroot-error-groups-parsing-failed = --groups parsing failed +chroot-error-invalid-group = invalid group: { $group } +chroot-error-invalid-group-list = invalid group list: { $list } +chroot-error-missing-newroot = Missing operand: NEWROOT\nTry '{ $util_name } --help' for more information. +chroot-error-no-group-specified = no group specified for unknown uid: { $uid } +chroot-error-no-such-user = invalid user +chroot-error-no-such-group = invalid group +chroot-error-no-such-directory = cannot change root directory to { $dir }: no such directory +chroot-error-set-gid-failed = cannot set gid to { $gid }: { $err } +chroot-error-set-groups-failed = cannot set groups: { $err } +chroot-error-set-user-failed = cannot set user to { $user }: { $err } diff --git a/src/uu/chroot/locales/fr-FR.ftl b/src/uu/chroot/locales/fr-FR.ftl new file mode 100644 index 000000000..3177fa839 --- /dev/null +++ b/src/uu/chroot/locales/fr-FR.ftl @@ -0,0 +1,24 @@ +chroot-about = Exécuter COMMANDE avec le répertoire racine défini à NOUVRACINE. +chroot-usage = chroot [OPTION]... NOUVRACINE [COMMANDE [ARG]...] + +# Messages d'aide +chroot-help-groups = Liste de groupes séparés par des virgules vers lesquels basculer +chroot-help-userspec = Utilisateur et groupe séparés par deux-points vers lesquels basculer. +chroot-help-skip-chdir = Utiliser cette option pour ne pas changer le répertoire de travail vers / après avoir changé le répertoire racine vers nouvracine, c.-à-d., à l'intérieur du chroot. + +# Messages d'erreur +chroot-error-skip-chdir-only-permitted = l'option --skip-chdir n'est autorisée que si NOUVRACINE est l'ancien '/' +chroot-error-cannot-enter = impossible de faire chroot vers { $dir } : { $err } +chroot-error-command-failed = échec de l'exécution de la commande { $cmd } : { $err } +chroot-error-command-not-found = échec de l'exécution de la commande { $cmd } : { $err } +chroot-error-groups-parsing-failed = échec de l'analyse de --groups +chroot-error-invalid-group = groupe invalide : { $group } +chroot-error-invalid-group-list = liste de groupes invalide : { $list } +chroot-error-missing-newroot = Opérande manquant : NOUVRACINE\nEssayez '{ $util_name } --help' pour plus d'informations. +chroot-error-no-group-specified = aucun groupe spécifié pour l'uid inconnu : { $uid } +chroot-error-no-such-user = utilisateur invalide +chroot-error-no-such-group = groupe invalide +chroot-error-no-such-directory = impossible de changer le répertoire racine vers { $dir } : aucun répertoire de ce type +chroot-error-set-gid-failed = impossible de définir le gid à { $gid } : { $err } +chroot-error-set-groups-failed = impossible de définir les groupes : { $err } +chroot-error-set-user-failed = impossible de définir l'utilisateur à { $user } : { $err } diff --git a/src/uu/chroot/src/chroot.rs b/src/uu/chroot/src/chroot.rs index 0b04e79ae..5d02384fb 100644 --- a/src/uu/chroot/src/chroot.rs +++ b/src/uu/chroot/src/chroot.rs @@ -76,7 +76,7 @@ fn parse_group_list(list_str: &str) -> Result, ChrootError> { let name = split[0].trim(); if name.is_empty() { // --groups=" " - // chroot: invalid group ‘ ’ + // chroot: invalid group ' ' Err(ChrootError::InvalidGroup(name.to_string())) } else { // --groups="blah" @@ -84,7 +84,7 @@ fn parse_group_list(list_str: &str) -> Result, ChrootError> { } } else if split.iter().all(|s| s.is_empty()) { // --groups="," - // chroot: invalid group list ‘,’ + // chroot: invalid group list ',' Err(ChrootError::InvalidGroupList(list_str.to_string())) } else { let mut result = vec![]; @@ -97,7 +97,7 @@ fn parse_group_list(list_str: &str) -> Result, ChrootError> { continue; } else { // --groups=", " - // chroot: invalid group ‘ ’ + // chroot: invalid group ' ' show!(ChrootError::InvalidGroup(name.to_string())); err = true; } @@ -107,7 +107,7 @@ fn parse_group_list(list_str: &str) -> Result, ChrootError> { && trimmed_name.ends_with(|c: char| !c.is_numeric()) { // --groups="0trail" - // chroot: invalid group ‘0trail’ + // chroot: invalid group '0trail' show!(ChrootError::InvalidGroup(name.to_string())); err = true; } else { @@ -176,7 +176,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { { return Err(UUsageError::new( 125, - "option --skip-chdir only permitted if NEWROOT is old '/'", + get_message("chroot-error-skip-chdir-only-permitted"), )); } @@ -251,23 +251,19 @@ pub fn uu_app() -> Command { Arg::new(options::GROUPS) .long(options::GROUPS) .overrides_with(options::GROUPS) - .help("Comma-separated list of groups to switch to") + .help(get_message("chroot-help-groups")) .value_name("GROUP1,GROUP2..."), ) .arg( Arg::new(options::USERSPEC) .long(options::USERSPEC) - .help("Colon-separated user and group to switch to.") + .help(get_message("chroot-help-userspec")) .value_name("USER:GROUP"), ) .arg( Arg::new(options::SKIP_CHDIR) .long(options::SKIP_CHDIR) - .help( - "Use this option to not change the working directory \ - to / after changing the root directory to newroot, \ - i.e., inside the chroot.", - ) + .help(get_message("chroot-help-skip-chdir")) .action(ArgAction::SetTrue), ) .arg( diff --git a/src/uu/chroot/src/error.rs b/src/uu/chroot/src/error.rs index 78fd7ad64..3a84f2837 100644 --- a/src/uu/chroot/src/error.rs +++ b/src/uu/chroot/src/error.rs @@ -4,68 +4,94 @@ // file that was distributed with this source code. // spell-checker:ignore NEWROOT Userspec userspec //! Errors returned by chroot. +use std::collections::HashMap; use std::io::Error; use thiserror::Error; use uucore::display::Quotable; use uucore::error::UError; use uucore::libc; +use uucore::locale::{get_message, get_message_with_args}; /// Errors that can happen while executing chroot. #[derive(Debug, Error)] pub enum ChrootError { /// Failed to enter the specified directory. - #[error("cannot chroot to {dir}: {err}", dir = .0.quote(), err = .1)] + #[error("{}", get_message_with_args("chroot-error-cannot-enter", HashMap::from([ + ("dir".to_string(), _0.quote().to_string()), + ("err".to_string(), _1.to_string()) + ])))] CannotEnter(String, #[source] Error), /// Failed to execute the specified command. - #[error("failed to run command {cmd}: {err}", cmd = .0.to_string().quote(), err = .1)] + #[error("{}", get_message_with_args("chroot-error-command-failed", HashMap::from([ + ("cmd".to_string(), _0.to_string().quote().to_string()), + ("err".to_string(), _1.to_string()) + ])))] CommandFailed(String, #[source] Error), /// Failed to find the specified command. - #[error("failed to run command {cmd}: {err}", cmd = .0.to_string().quote(), err = .1)] + #[error("{}", get_message_with_args("chroot-error-command-not-found", HashMap::from([ + ("cmd".to_string(), _0.to_string().quote().to_string()), + ("err".to_string(), _1.to_string()) + ])))] CommandNotFound(String, #[source] Error), - #[error("--groups parsing failed")] + #[error("{}", get_message("chroot-error-groups-parsing-failed"))] GroupsParsingFailed, - #[error("invalid group: {group}", group = .0.quote())] + #[error("{}", get_message_with_args("chroot-error-invalid-group", HashMap::from([ + ("group".to_string(), _0.quote().to_string()) + ])))] InvalidGroup(String), - #[error("invalid group list: {list}", list = .0.quote())] + #[error("{}", get_message_with_args("chroot-error-invalid-group-list", HashMap::from([ + ("list".to_string(), _0.quote().to_string()) + ])))] InvalidGroupList(String), /// The new root directory was not given. - #[error( - "Missing operand: NEWROOT\nTry '{0} --help' for more information.", - uucore::execution_phrase() - )] + #[error("{}", get_message_with_args("chroot-error-missing-newroot", HashMap::from([ + ("util_name".to_string(), uucore::execution_phrase().to_string()) + ])))] MissingNewRoot, - #[error("no group specified for unknown uid: {0}")] + #[error("{}", get_message_with_args("chroot-error-no-group-specified", HashMap::from([ + ("uid".to_string(), _0.to_string()) + ])))] NoGroupSpecified(libc::uid_t), /// Failed to find the specified user. - #[error("invalid user")] + #[error("{}", get_message("chroot-error-no-such-user"))] NoSuchUser, /// Failed to find the specified group. - #[error("invalid group")] + #[error("{}", get_message("chroot-error-no-such-group"))] NoSuchGroup, /// The given directory does not exist. - #[error("cannot change root directory to {dir}: no such directory", dir = .0.quote())] + #[error("{}", get_message_with_args("chroot-error-no-such-directory", HashMap::from([ + ("dir".to_string(), _0.quote().to_string()) + ])))] NoSuchDirectory(String), /// The call to `setgid()` failed. - #[error("cannot set gid to {gid}: {err}", gid = .0, err = .1)] + #[error("{}", get_message_with_args("chroot-error-set-gid-failed", HashMap::from([ + ("gid".to_string(), _0.to_string()), + ("err".to_string(), _1.to_string()) + ])))] SetGidFailed(String, #[source] Error), /// The call to `setgroups()` failed. - #[error("cannot set groups: {0}")] + #[error("{}", get_message_with_args("chroot-error-set-groups-failed", HashMap::from([ + ("err".to_string(), _0.to_string()) + ])))] SetGroupsFailed(Error), /// The call to `setuid()` failed. - #[error("cannot set user to {user}: {err}", user = .0.maybe_quote(), err = .1)] + #[error("{}", get_message_with_args("chroot-error-set-user-failed", HashMap::from([ + ("user".to_string(), _0.maybe_quote().to_string()), + ("err".to_string(), _1.to_string()) + ])))] SetUserFailed(String, #[source] Error), }