Browse Source

Remove unwrap from append logic

pull/10/head
Fenrir 8 years ago
parent
commit
c3da19784f
  1. 13
      src/services/fs.rs

13
src/services/fs.rs

@ -520,22 +520,17 @@ impl OpenOptions {
let mut file = File { handle: file_handle, offset: 0 }; 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 { 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, // set the offset to 0 just in case both append and truncate were
// so let's use try! // set to true
//
// But let's also set the offset to 0 just in case both
// append and truncate are true
if self.truncate { if self.truncate {
try!(file.set_len(0)); try!(file.set_len(0));
file.offset = 0; file.offset = 0;
} }
Ok(file) Ok(file)
} }
} }

Loading…
Cancel
Save