Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize and another test for directory-permissions handling #4286

Merged
merged 18 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pub fn make_temp(
}

pub fn mkdir(path: &Path, mode: u32, recursive: bool) -> std::io::Result<()> {
debug!("mkdir -p {}", path.display());
let mut builder = DirBuilder::new();
builder.recursive(recursive);
set_dir_permission(&mut builder, mode);
Expand All @@ -104,8 +103,9 @@ pub fn mkdir(path: &Path, mode: u32, recursive: bool) -> std::io::Result<()> {

#[cfg(unix)]
fn set_dir_permission(builder: &mut DirBuilder, mode: u32) {
debug!("set dir mode to {}", mode);
builder.mode(mode & 0o777);
let mode = mode & 0o777;
debug!("set dir mode to {:o}", mode);
builder.mode(mode);
}

#[cfg(not(unix))]
Expand Down
6 changes: 4 additions & 2 deletions cli/js/mkdir.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "./ops/dispatch_json.ts";

type MkdirArgs = { path: string; recursive: boolean; mode?: number };

// TODO(ry) The complexity in argument parsing is to support deprecated forms of
// mkdir and mkdirSync.
function mkdirArgs(
path: string,
optionsOrRecursive?: MkdirOptions | boolean,
mode?: number
): { path: string; recursive: boolean; mode: number } {
const args = { path, recursive: false, mode: 0o777 };
): MkdirArgs {
const args: MkdirArgs = { path, recursive: false };
if (typeof optionsOrRecursive == "boolean") {
args.recursive = optionsOrRecursive;
if (mode) {
Expand Down
5 changes: 3 additions & 2 deletions cli/js/mkdir_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ unitTest(
{ perms: { read: true, write: true } },
function mkdirSyncMode(): void {
const path = Deno.makeTempDirSync() + "/dir";
Deno.mkdirSync(path, { mode: 0o755 }); // no perm for x
Deno.mkdirSync(path, { mode: 0o737 });
const pathInfo = Deno.statSync(path);
if (pathInfo.mode !== null) {
// Skip windows
assertEquals(pathInfo.mode & 0o777, 0o755);
// assertEquals(pathInfo.mode, 0o737 & ~Deno.umask());
assertEquals(pathInfo.mode & 0o777, 0o715); // assume umask 0o022
dubiousjim marked this conversation as resolved.
Show resolved Hide resolved
}
}
);
Expand Down
7 changes: 4 additions & 3 deletions cli/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ struct MkdirArgs {
promise_id: Option<u64>,
path: String,
recursive: bool,
mode: u32,
mode: Option<u32>,
}

fn op_mkdir(
Expand All @@ -252,13 +252,14 @@ fn op_mkdir(
) -> Result<JsonOp, OpError> {
let args: MkdirArgs = serde_json::from_value(args)?;
let path = deno_fs::resolve_from_cwd(Path::new(&args.path))?;
let mode = args.mode.unwrap_or(0o777);

state.check_write(&path)?;

let is_sync = args.promise_id.is_none();
blocking_json(is_sync, move || {
debug!("op_mkdir {}", path.display());
deno_fs::mkdir(&path, args.mode, args.recursive)?;
debug!("op_mkdir {} {:o} {}", path.display(), mode, args.recursive);
deno_fs::mkdir(&path, mode, args.recursive)?;
Ok(json!({}))
})
}
Expand Down