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/mkdir/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
mkdir-about = Create the given DIRECTORY(ies) if they do not exist
mkdir-usage = mkdir [OPTION]... DIRECTORY...
mkdir-after-help = Each MODE is of the form [ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+.

# Help messages
mkdir-help-mode = set file mode (not implemented on windows)
mkdir-help-parents = make parent directories as needed
mkdir-help-verbose = print a message for each printed directory
mkdir-help-selinux = set SELinux security context of each created directory to the default type
mkdir-help-context = like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX

# Error messages
mkdir-error-empty-directory-name = cannot create directory '': No such file or directory
mkdir-error-file-exists = { $path }: File exists
mkdir-error-failed-to-create-tree = failed to create whole tree
mkdir-error-cannot-set-permissions = cannot set permissions { $path }

# Verbose output
mkdir-verbose-created-directory = { $util_name }: created directory { $path }
19 changes: 19 additions & 0 deletions src/uu/mkdir/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
mkdir-about = Créer les RÉPERTOIRE(s) donnés s'ils n'existent pas
mkdir-usage = mkdir [OPTION]... RÉPERTOIRE...
mkdir-after-help = Chaque MODE est de la forme [ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+.

# Messages d'aide
mkdir-help-mode = définir le mode de fichier (non implémenté sur Windows)
mkdir-help-parents = créer les répertoires parents si nécessaire
mkdir-help-verbose = afficher un message pour chaque répertoire créé
mkdir-help-selinux = définir le contexte de sécurité SELinux de chaque répertoire créé au type par défaut
mkdir-help-context = comme -Z, ou si CTX est spécifié, définir le contexte de sécurité SELinux ou SMACK à CTX

# Messages d'erreur
mkdir-error-empty-directory-name = impossible de créer le répertoire '' : Aucun fichier ou répertoire de ce type
mkdir-error-file-exists = { $path } : Le fichier existe
mkdir-error-failed-to-create-tree = échec de la création de l'arborescence complète
mkdir-error-cannot-set-permissions = impossible de définir les permissions { $path }

# Sortie détaillée
mkdir-verbose-created-directory = { $util_name } : répertoire créé { $path }
49 changes: 32 additions & 17 deletions src/uu/mkdir/src/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use clap::builder::ValueParser;
use clap::parser::ValuesRef;
use clap::{Arg, ArgAction, ArgMatches, Command};
use std::collections::HashMap;
use std::ffi::OsString;
use std::path::{Path, PathBuf};
#[cfg(not(windows))]
use uucore::error::FromIo;
use uucore::error::{UResult, USimpleError};
use uucore::locale::get_message;
use uucore::locale::{get_message, get_message_with_args};
#[cfg(not(windows))]
use uucore::mode;
use uucore::{display::Quotable, fs::dir_strip_dot_for_creation};
Expand Down Expand Up @@ -139,32 +140,35 @@
Arg::new(options::MODE)
.short('m')
.long(options::MODE)
.help("set file mode (not implemented on windows)"),
.help(get_message("mkdir-help-mode")),
)
.arg(
Arg::new(options::PARENTS)
.short('p')
.long(options::PARENTS)
.help("make parent directories as needed")
.help(get_message("mkdir-help-parents"))
.overrides_with(options::PARENTS)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::VERBOSE)
.short('v')
.long(options::VERBOSE)
.help("print a message for each printed directory")
.help(get_message("mkdir-help-verbose"))
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::SELINUX)
.short('Z')
.help("set SELinux security context of each created directory to the default type")
.help(get_message("mkdir-help-selinux"))
.action(ArgAction::SetTrue),
)
.arg(Arg::new(options::CONTEXT).long(options::CONTEXT).value_name("CTX").help(
"like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX",
))
.arg(
Arg::new(options::CONTEXT)
.long(options::CONTEXT)
.value_name("CTX")
.help(get_message("mkdir-help-context")),
)
.arg(
Arg::new(options::DIRS)
.action(ArgAction::Append)
Expand Down Expand Up @@ -205,10 +209,9 @@
if path.as_os_str().is_empty() {
return Err(USimpleError::new(
1,
"cannot create directory '': No such file or directory".to_owned(),
get_message("mkdir-error-empty-directory-name"),
));
}

// Special case to match GNU's behavior:
// mkdir -p foo/. should work and just create foo/
// std::fs::create_dir("foo/."); fails in pure Rust
Expand All @@ -222,8 +225,12 @@
use std::fs::{Permissions, set_permissions};
use std::os::unix::fs::PermissionsExt;
let mode = Permissions::from_mode(mode);
set_permissions(path, mode)
.map_err_context(|| format!("cannot set permissions {}", path.quote()))
set_permissions(path, mode).map_err_context(|| {
get_message_with_args(
"mkdir-error-cannot-set-permissions",
HashMap::from([("path".to_string(), path.quote().to_string())]),

Check warning on line 231 in src/uu/mkdir/src/mkdir.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkdir/src/mkdir.rs#L229-L231

Added lines #L229 - L231 were not covered by tests
)
})

Check warning on line 233 in src/uu/mkdir/src/mkdir.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkdir/src/mkdir.rs#L233

Added line #L233 was not covered by tests
}

#[cfg(windows)]
Expand All @@ -240,7 +247,10 @@
if path_exists && !config.recursive {
return Err(USimpleError::new(
1,
format!("{}: File exists", path.display()),
get_message_with_args(
"mkdir-error-file-exists",
HashMap::from([("path".to_string(), path.to_string_lossy().to_string())]),
),
));
}
if path == Path::new("") {
Expand All @@ -251,7 +261,7 @@
match path.parent() {
Some(p) => create_dir(p, true, config)?,
None => {
USimpleError::new(1, "failed to create whole tree");
USimpleError::new(1, get_message("mkdir-error-failed-to-create-tree"));

Check warning on line 264 in src/uu/mkdir/src/mkdir.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkdir/src/mkdir.rs#L264

Added line #L264 was not covered by tests
}
}
}
Expand All @@ -260,9 +270,14 @@
Ok(()) => {
if config.verbose {
println!(
"{}: created directory {}",
uucore::util_name(),
path.quote()
"{}",
get_message_with_args(
"mkdir-verbose-created-directory",
HashMap::from([
("util_name".to_string(), uucore::util_name().to_string()),
("path".to_string(), path.quote().to_string())
])
)
);
}

Expand Down
Loading