Skip to content

Commit 7a9b880

Browse files
committed
mkdir: strip_minus_from_mode: Use uucore functions
Let's not reinvent stuff.
1 parent 98f3aac commit 7a9b880

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/uu/mkdir/src/mkdir.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use clap::parser::ValuesRef;
1010
use clap::{Arg, ArgAction, ArgMatches, Command};
1111
use std::collections::HashMap;
1212
use std::ffi::OsString;
13-
use std::os::unix::ffi::OsStrExt;
1413
use std::path::{Path, PathBuf};
1514
#[cfg(not(windows))]
1615
use uucore::error::FromIo;
@@ -82,31 +81,31 @@ fn get_mode(matches: &ArgMatches, mode_had_minus_prefix: bool) -> Result<u32, St
8281
}
8382

8483
#[cfg(windows)]
85-
fn strip_minus_from_mode(_args: &mut [OsString]) -> bool {
86-
false
84+
fn strip_minus_from_mode(_args: &mut [OsString]) -> UResult<bool> {
85+
Ok(false)
8786
}
8887

8988
// Iterate 'args' and delete the first occurrence
9089
// of a prefix '-' if it's associated with MODE
9190
// e.g. "chmod -v -xw -R FILE" -> "chmod -v xw -R FILE"
9291
#[cfg(not(windows))]
93-
fn strip_minus_from_mode(args: &mut Vec<OsString>) -> bool {
92+
fn strip_minus_from_mode(args: &mut Vec<OsString>) -> UResult<bool> {
9493
for arg in args {
9594
if arg == "--" {
9695
break;
9796
}
98-
let bytes = arg.as_bytes();
97+
let bytes = uucore::os_str_as_bytes(arg)?;
9998
if let Some(b'-') = bytes.first() {
10099
if let Some(
101100
b'r' | b'w' | b'x' | b'X' | b's' | b't' | b'u' | b'g' | b'o' | b'0'..=b'7',
102101
) = bytes.get(1)
103102
{
104-
*arg = std::ffi::OsStr::from_bytes(&bytes[1..]).to_owned();
105-
return true;
103+
*arg = uucore::os_str_from_bytes(&bytes[1..])?.into_owned();
104+
return Ok(true);
106105
}
107106
}
108107
}
109-
false
108+
Ok(false)
110109
}
111110

112111
#[uucore::main]
@@ -115,7 +114,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
115114

116115
// Before we can parse 'args' with clap (and previously getopts),
117116
// a possible MODE prefix '-' needs to be removed (e.g. "chmod -x FILE").
118-
let mode_had_minus_prefix = strip_minus_from_mode(&mut args);
117+
let mode_had_minus_prefix = strip_minus_from_mode(&mut args)?;
119118

120119
// Linux-specific options, not implemented
121120
// opts.optflag("Z", "context", "set SELinux security context" +

0 commit comments

Comments
 (0)