Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace expect with a safer alternative that returns None instead #240

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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