Skip to content

Commit

Permalink
Merge pull request #240 from costinsin/fix_expect
Browse files Browse the repository at this point in the history
Replace `expect` with a safer alternative that returns `None` instead
  • Loading branch information
pyrossh authored Apr 5, 2024
2 parents f7c7268 + 73dab7b commit a735c9e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,17 @@ pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
};

let metadata = fs::metadata(file_path)?;
let last_modified = metadata.modified().ok().map(|last_modified| {
last_modified
.duration_since(SystemTime::UNIX_EPOCH)
.expect("Time before the UNIX epoch is unsupported")
.as_secs()
});
let created = metadata.created().ok().map(|created| {
created
.duration_since(SystemTime::UNIX_EPOCH)
.expect("Time before the UNIX epoch is unsupported")
.as_secs()
});
let last_modified = metadata
.modified()
.ok()
.and_then(|modified| modified.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|secs| secs.as_secs());

let created = metadata
.created()
.ok()
.and_then(|created| created.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|secs| secs.as_secs());

#[cfg(feature = "mime-guess")]
let mimetype = mime_guess::from_path(file_path).first_or_octet_stream().to_string();
Expand Down

0 comments on commit a735c9e

Please sign in to comment.