diff options
Diffstat (limited to 'cli/ops/fs.rs')
-rw-r--r-- | cli/ops/fs.rs | 85 |
1 files changed, 15 insertions, 70 deletions
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<String, OpError> { struct OpenArgs { promise_id: Option<u64>, path: String, - options: Option<OpenOptions>, - open_mode: Option<String>, + options: OpenOptions, mode: Option<u32>, } @@ -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(); |