summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-01-17 23:39:06 -0500
committerGitHub <noreply@github.com>2019-01-17 23:39:06 -0500
commit315e4abd7e88c428e78c006ccf2dfdb499911a05 (patch)
treeb48136d6f0437374c5c0a9a8f717f7495b5ff808 /src
parentd06c95637a2a19588fcb549ed7b760a916b3cbfd (diff)
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 <sdo451@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/deno_dir.rs10
-rw-r--r--src/fs.rs9
-rw-r--r--src/msg.fbs7
-rw-r--r--src/ops.rs6
4 files changed, 16 insertions, 16 deletions
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<Op> {
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())
})
}