diff options
author | F001 <changchun.fan@qq.com> | 2018-12-14 16:29:17 +0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-14 03:29:17 -0500 |
commit | 0bb43ebbfcbc378810f75c43a2be3369729921f7 (patch) | |
tree | a08d3e6ee297582b1cc65a4af4aba947cdab14c8 /src | |
parent | a60da6462621b2f1ddf12dda4cd205c06179c6b1 (diff) |
remove repeative permission checks (#1350)
Diffstat (limited to 'src')
-rw-r--r-- | src/ops.rs | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/ops.rs b/src/ops.rs index 3dc457aa6..44c1f8702 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -594,21 +594,12 @@ fn op_open( open_options.read(true); } "r+" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options.read(true).write(true); } "w" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options.create(true).write(true).truncate(true); } "w+" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options .read(true) .create(true) @@ -616,27 +607,15 @@ fn op_open( .truncate(true); } "a" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options.create(true).append(true); } "a+" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options.read(true).create(true).append(true); } "x" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options.create_new(true).write(true); } "x+" => { - if let Err(e) = state.check_write(&filename_str) { - return odd_future(e); - } open_options.create_new(true).read(true).write(true); } &_ => { @@ -644,6 +623,13 @@ fn op_open( } } + if mode != "r" { + // Write permission is needed except "r" mode + if let Err(e) = state.check_write(&filename_str) { + return odd_future(e); + } + } + let op = open_options .open(filename) .map_err(DenoError::from) |