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
11 changes: 11 additions & 0 deletions src/uu/mkfifo/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
mkfifo-about = Create a FIFO with the given name.
mkfifo-usage = mkfifo [OPTION]... NAME...

# Help messages
mkfifo-help-mode = file permissions for the fifo
mkfifo-help-selinux = set the SELinux security context to default type
mkfifo-help-context = like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX

# Error messages
mkfifo-error-invalid-mode = invalid mode: { $error }
mkfifo-error-missing-operand = missing operand
mkfifo-error-cannot-create-fifo = cannot create fifo { $path }: File exists
mkfifo-error-cannot-set-permissions = cannot set permissions on { $path }: { $error }
13 changes: 13 additions & 0 deletions src/uu/mkfifo/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mkfifo-about = Créer un FIFO avec le nom donné.
mkfifo-usage = mkfifo [OPTION]... NOM...

# Messages d'aide
mkfifo-help-mode = permissions de fichier pour le fifo
mkfifo-help-selinux = définir le contexte de sécurité SELinux au type par défaut
mkfifo-help-context = comme -Z, ou si CTX est spécifié, définir le contexte de sécurité SELinux ou SMACK à CTX

# Messages d'erreur
mkfifo-error-invalid-mode = mode invalide : { $error }
mkfifo-error-missing-operand = opérande manquant
mkfifo-error-cannot-create-fifo = impossible de créer le fifo { $path } : Le fichier existe
mkfifo-error-cannot-set-permissions = impossible de définir les permissions sur { $path } : { $error }
43 changes: 31 additions & 12 deletions src/uu/mkfifo/src/mkfifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

use clap::{Arg, ArgAction, Command, value_parser};
use libc::mkfifo;
use std::collections::HashMap;
use std::ffi::CString;
use std::fs;
use std::os::unix::fs::PermissionsExt;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::locale::{get_message, get_message_with_args};
use uucore::{format_usage, show};

use uucore::locale::get_message;

mod options {
pub static MODE: &str = "mode";
pub static SELINUX: &str = "Z";
Expand All @@ -29,15 +29,28 @@
// if mode is passed, ignore umask
Some(m) => match usize::from_str_radix(m, 8) {
Ok(m) => m,
Err(e) => return Err(USimpleError::new(1, format!("invalid mode: {e}"))),
Err(e) => {
return Err(USimpleError::new(
1,
get_message_with_args(
"mkfifo-error-invalid-mode",
HashMap::from([("error".to_string(), e.to_string())]),
),
));

Check warning on line 39 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L32-L39

Added lines #L32 - L39 were not covered by tests
}
},
// Default value + umask if present
None => 0o666 & !(uucore::mode::get_umask() as usize),
};

let fifos: Vec<String> = match matches.get_many::<String>(options::FIFO) {
Some(v) => v.cloned().collect(),
None => return Err(USimpleError::new(1, "missing operand")),
None => {
return Err(USimpleError::new(
1,
get_message("mkfifo-error-missing-operand"),
));

Check warning on line 52 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L49-L52

Added lines #L49 - L52 were not covered by tests
}
};

for f in fifos {
Expand All @@ -48,15 +61,24 @@
if err == -1 {
show!(USimpleError::new(
1,
format!("cannot create fifo {}: File exists", f.quote()),
get_message_with_args(
"mkfifo-error-cannot-create-fifo",
HashMap::from([("path".to_string(), f.quote().to_string())]),
),

Check warning on line 67 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L64-L67

Added lines #L64 - L67 were not covered by tests
));
}

// Explicitly set the permissions to ignore umask
if let Err(e) = fs::set_permissions(&f, fs::Permissions::from_mode(mode as u32)) {
return Err(USimpleError::new(
1,
format!("cannot set permissions on {}: {e}", f.quote()),
get_message_with_args(
"mkfifo-error-cannot-set-permissions",
HashMap::from([
("path".to_string(), f.quote().to_string()),
("error".to_string(), e.to_string()),
]),
),

Check warning on line 81 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L75-L81

Added lines #L75 - L81 were not covered by tests
));
}

Expand Down Expand Up @@ -92,13 +114,13 @@
Arg::new(options::MODE)
.short('m')
.long(options::MODE)
.help("file permissions for the fifo")
.help(get_message("mkfifo-help-mode"))

Check warning on line 117 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L117

Added line #L117 was not covered by tests
.value_name("MODE"),
)
.arg(
Arg::new(options::SELINUX)
.short('Z')
.help("set the SELinux security context to default type")
.help(get_message("mkfifo-help-selinux"))

Check warning on line 123 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L123

Added line #L123 was not covered by tests
.action(ArgAction::SetTrue),
)
.arg(
Expand All @@ -108,10 +130,7 @@
.value_parser(value_parser!(String))
.num_args(0..=1)
.require_equals(true)
.help(
"like -Z, or if CTX is specified then set the SELinux \
or SMACK security context to CTX",
),
.help(get_message("mkfifo-help-context")),

Check warning on line 133 in src/uu/mkfifo/src/mkfifo.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/mkfifo/src/mkfifo.rs#L133

Added line #L133 was not covered by tests
)
.arg(
Arg::new(options::FIFO)
Expand Down
Loading