summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/deno_dir.rs4
-rw-r--r--src/fs.rs30
-rw-r--r--src/handlers.rs5
3 files changed, 25 insertions, 14 deletions
diff --git a/src/deno_dir.rs b/src/deno_dir.rs
index a8379b900..53fbf5ba8 100644
--- a/src/deno_dir.rs
+++ b/src/deno_dir.rs
@@ -55,8 +55,8 @@ impl DenoDir {
deps,
reload,
};
- deno_fs::mkdir(deno_dir.gen.as_ref())?;
- deno_fs::mkdir(deno_dir.deps.as_ref())?;
+ deno_fs::mkdir(deno_dir.gen.as_ref(), 0o755)?;
+ deno_fs::mkdir(deno_dir.deps.as_ref(), 0o755)?;
debug!("root {}", deno_dir.root.display());
debug!("gen {}", deno_dir.gen.display());
diff --git a/src/fs.rs b/src/fs.rs
index e04675f66..33323b87b 100644
--- a/src/fs.rs
+++ b/src/fs.rs
@@ -1,5 +1,5 @@
use std;
-use std::fs::{create_dir, File, OpenOptions};
+use std::fs::{create_dir, DirBuilder, File, OpenOptions};
use std::io::ErrorKind;
use std::io::Write;
use std::path::{Path, PathBuf};
@@ -8,6 +8,8 @@ use rand;
use rand::Rng;
#[cfg(any(unix))]
+use std::os::unix::fs::DirBuilderExt;
+#[cfg(any(unix))]
use std::os::unix::fs::PermissionsExt;
pub fn write_file(
@@ -64,18 +66,28 @@ pub fn make_temp_dir(
}
}
-pub fn mkdir(path: &Path) -> std::io::Result<()> {
+pub fn mkdir(path: &Path, perm: u32) -> std::io::Result<()> {
debug!("mkdir -p {}", path.display());
- assert!(path.has_root(), "non-has_root not yet implemented");
- std::fs::create_dir_all(path).or_else(|err| {
- if err.kind() == std::io::ErrorKind::AlreadyExists {
- Ok(())
- } else {
- Err(err)
- }
+ let mut builder = DirBuilder::new();
+ builder.recursive(true);
+ set_dir_permission(&mut builder, perm);
+ builder.create(path).or_else(|err| match err.kind() {
+ std::io::ErrorKind::AlreadyExists => Ok(()),
+ _ => Err(err),
})
}
+#[cfg(any(unix))]
+fn set_dir_permission(builder: &mut DirBuilder, perm: u32) {
+ debug!("set dir perm to {}", perm);
+ builder.mode(perm);
+}
+
+#[cfg(not(any(unix)))]
+fn set_dir_permission(_builder: &mut DirBuilder, _perm: u32) {
+ // NOOP on windows
+}
+
pub fn normalize_path(path: &Path) -> String {
let s = String::from(path.to_str().unwrap());
if cfg!(windows) {
diff --git a/src/handlers.rs b/src/handlers.rs
index 641bfd83c..0917fd22a 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -451,7 +451,7 @@ fn handle_make_temp_dir(d: *const DenoC, base: &msg::Base) -> Box<Op> {
fn handle_mkdir(d: *const DenoC, base: &msg::Base) -> Box<Op> {
let msg = base.msg_as_mkdir().unwrap();
- // TODO let mode = msg.mode();
+ let mode = msg.mode();
let path = msg.path().unwrap();
let deno = from_c(d);
if !deno.flags.allow_write {
@@ -460,8 +460,7 @@ fn handle_mkdir(d: *const DenoC, base: &msg::Base) -> Box<Op> {
// TODO Use tokio_threadpool.
Box::new(futures::future::result(|| -> OpResult {
debug!("handle_mkdir {}", path);
- // TODO(ry) Use mode.
- deno_fs::mkdir(Path::new(path))?;
+ deno_fs::mkdir(Path::new(path), mode)?;
Ok(None)
}()))
}