Skip to content

Commit 3f694fa

Browse files
authored
Merge pull request #6802 from andrewliebenow/mkdir-empty-argument-fix
mkdir: emit error when path is empty
2 parents 5b881a0 + 80b6393 commit 3f694fa

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/uu/mkdir/src/mkdir.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ fn exec(dirs: ValuesRef<OsString>, recursive: bool, mode: u32, verbose: bool) ->
160160
/// To match the GNU behavior, a path with the last directory being a single dot
161161
/// (like `some/path/to/.`) is created (with the dot stripped).
162162
pub fn mkdir(path: &Path, recursive: bool, mode: u32, verbose: bool) -> UResult<()> {
163+
if path.as_os_str().is_empty() {
164+
return Err(USimpleError::new(
165+
1,
166+
"cannot create directory '': No such file or directory".to_owned(),
167+
));
168+
}
169+
163170
// Special case to match GNU's behavior:
164171
// mkdir -p foo/. should work and just create foo/
165172
// std::fs::create_dir("foo/."); fails in pure Rust

tests/by-util/test_mkdir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5+
6+
// spell-checker:ignore bindgen
7+
58
#![allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
69

710
use crate::common::util::TestScenario;
@@ -332,3 +335,11 @@ fn test_umask_compliance() {
332335
test_single_case(i as mode_t);
333336
}
334337
}
338+
339+
#[test]
340+
fn test_empty_argument() {
341+
new_ucmd!()
342+
.arg("")
343+
.fails()
344+
.stderr_only("mkdir: cannot create directory '': No such file or directory\n");
345+
}

0 commit comments

Comments
 (0)