From c3da19784f631c0492a1d61f1bb0b1353cdd1e5d Mon Sep 17 00:00:00 2001 From: Fenrir Date: Fri, 30 Sep 2016 00:06:01 -0700 Subject: [PATCH] Remove unwrap from append logic --- src/services/fs.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/services/fs.rs b/src/services/fs.rs index ef4949a..6bca22a 100644 --- a/src/services/fs.rs +++ b/src/services/fs.rs @@ -520,22 +520,17 @@ impl OpenOptions { let mut file = File { handle: file_handle, offset: 0 }; - // We have write access if append is true, so we *should* be - // fine unwrapping here if self.append { - file.offset = file.metadata().unwrap().len(); + let metadata = try!(file.metadata()); + file.offset = metadata.len(); } - // we might not have write access even if truncate is true, - // so let's use try! - // - // But let's also set the offset to 0 just in case both - // append and truncate are true + // set the offset to 0 just in case both append and truncate were + // set to true if self.truncate { try!(file.set_len(0)); file.offset = 0; } - Ok(file) } }