From 315e4abd7e88c428e78c006ccf2dfdb499911a05 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 17 Jan 2019 23:39:06 -0500 Subject: mkdir should not be recursive by default (#1530) It should return an error if a file with the given path exists and recursive isn't specified. Because mode is not used on windows and rarely used in unix, it is made to the last parameter. In collaboration with Stefan Dombrowski --- src/deno_dir.rs | 10 ++++++---- src/fs.rs | 9 +++------ src/msg.fbs | 7 +++---- src/ops.rs | 6 ++++-- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/deno_dir.rs b/src/deno_dir.rs index fa1bff955..5c7e2f9e8 100644 --- a/src/deno_dir.rs +++ b/src/deno_dir.rs @@ -73,10 +73,12 @@ impl DenoDir { deps_https, reload, }; - deno_fs::mkdir(deno_dir.gen.as_ref(), 0o755)?; - deno_fs::mkdir(deno_dir.deps.as_ref(), 0o755)?; - deno_fs::mkdir(deno_dir.deps_http.as_ref(), 0o755)?; - deno_fs::mkdir(deno_dir.deps_https.as_ref(), 0o755)?; + + // TODO Lazily create these directories. + deno_fs::mkdir(deno_dir.gen.as_ref(), 0o755, true)?; + deno_fs::mkdir(deno_dir.deps.as_ref(), 0o755, true)?; + deno_fs::mkdir(deno_dir.deps_http.as_ref(), 0o755, true)?; + deno_fs::mkdir(deno_dir.deps_https.as_ref(), 0o755, true)?; debug!("root {}", deno_dir.root.display()); debug!("gen {}", deno_dir.gen.display()); diff --git a/src/fs.rs b/src/fs.rs index 1b860b057..9748cffab 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -67,15 +67,12 @@ pub fn make_temp_dir( } } -pub fn mkdir(path: &Path, perm: u32) -> std::io::Result<()> { +pub fn mkdir(path: &Path, perm: u32, recursive: bool) -> std::io::Result<()> { debug!("mkdir -p {}", path.display()); let mut builder = DirBuilder::new(); - builder.recursive(true); + builder.recursive(recursive); set_dir_permission(&mut builder, perm); - builder.create(path).or_else(|err| match err.kind() { - std::io::ErrorKind::AlreadyExists => Ok(()), - _ => Err(err), - }) + builder.create(path) } #[cfg(any(unix))] diff --git a/src/msg.fbs b/src/msg.fbs index 57f8a7f2c..4b303535f 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -260,14 +260,13 @@ table MakeTempDirRes { table Mkdir { path: string; - mode: uint; - // mode specified by https://godoc.org/os#FileMode + recursive: bool; + mode: uint; // Specified by https://godoc.org/os#FileMode } table Chmod { path: string; - mode: uint; - // mode specified by https://godoc.org/os#FileMode + mode: uint; // Specified by https://godoc.org/os#FileMode } table Remove { diff --git a/src/ops.rs b/src/ops.rs index abc7b8d34..f3c80e1ac 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -540,15 +540,17 @@ fn op_mkdir( ) -> Box { assert_eq!(data.len(), 0); let inner = base.inner_as_mkdir().unwrap(); - let mode = inner.mode(); let path = String::from(inner.path().unwrap()); + let recursive = inner.recursive(); + let mode = inner.mode(); if let Err(e) = state.check_write(&path) { return odd_future(e); } + blocking(base.sync(), move || { debug!("op_mkdir {}", path); - deno_fs::mkdir(Path::new(&path), mode)?; + deno_fs::mkdir(Path::new(&path), mode, recursive)?; Ok(empty_buf()) }) } -- cgit v1.2.3