1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 17:19:06 -05:00

remove repeative permission checks (#1350)

This commit is contained in:
F001 2018-12-14 16:29:17 +08:00 committed by Ryan Dahl
parent a60da64626
commit 0bb43ebbfc

View file

@ -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)