From 4a8d25646aa58e3e59d622e69c41822b40415c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 25 Apr 2020 00:45:55 +0200 Subject: BREAKING CHANGE: remove Deno.OpenMode (#4884) This commit removes Deno.OpenMode along with overloaded variants of Deno.open() and Deno.openSync() that used OpenMode. --- cli/ops/fs.rs | 85 +++++++++++------------------------------------------------ 1 file changed, 15 insertions(+), 70 deletions(-) (limited to 'cli/ops') diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index a7f7fbf08..6b259e033 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -50,8 +50,7 @@ fn into_string(s: std::ffi::OsString) -> Result { struct OpenArgs { promise_id: Option, path: String, - options: Option, - open_mode: Option, + options: OpenOptions, mode: Option, } @@ -91,76 +90,22 @@ fn op_open( let _ = mode; // avoid unused warning } - if let Some(options) = args.options { - if options.read { - state.check_read(&path)?; - } - - if options.write || options.append { - state.check_write(&path)?; - } + let options = args.options; + if options.read { + state.check_read(&path)?; + } - open_options - .read(options.read) - .create(options.create) - .write(options.write) - .truncate(options.truncate) - .append(options.append) - .create_new(options.create_new); - } else if let Some(open_mode) = args.open_mode { - let open_mode = open_mode.as_ref(); - match open_mode { - "r" => { - state.check_read(&path)?; - } - "w" | "a" | "x" => { - state.check_write(&path)?; - } - &_ => { - state.check_read(&path)?; - state.check_write(&path)?; - } - }; + if options.write || options.append { + state.check_write(&path)?; + } - match open_mode { - "r" => { - open_options.read(true); - } - "r+" => { - open_options.read(true).write(true); - } - "w" => { - open_options.create(true).write(true).truncate(true); - } - "w+" => { - open_options - .read(true) - .create(true) - .write(true) - .truncate(true); - } - "a" => { - open_options.create(true).append(true); - } - "a+" => { - open_options.read(true).create(true).append(true); - } - "x" => { - open_options.create_new(true).write(true); - } - "x+" => { - open_options.create_new(true).read(true).write(true); - } - &_ => { - // TODO: this should be type error - return Err(OpError::other("Unknown open mode.".to_string())); - } - } - } else { - return Err(OpError::other( - "Open requires either openMode or options.".to_string(), - )); - }; + open_options + .read(options.read) + .create(options.create) + .write(options.write) + .truncate(options.truncate) + .append(options.append) + .create_new(options.create_new); let is_sync = args.promise_id.is_none(); -- cgit v1.2.3