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

unix/birthtime: use broad support of libstd #100

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 10 additions & 27 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,17 @@ pub fn from_last_access_time(meta: &fs::Metadata) -> FileTime {
}

pub fn from_creation_time(meta: &fs::Metadata) -> Option<FileTime> {
macro_rules! birthtim {
($(($e:expr, $i:ident)),*) => {
#[cfg(any($(target_os = $e),*))]
fn imp(meta: &fs::Metadata) -> Option<FileTime> {
$(
#[cfg(target_os = $e)]
use std::os::$i::fs::MetadataExt;
)*
Some(FileTime {
seconds: meta.st_birthtime(),
nanos: meta.st_birthtime_nsec() as u32,
})
}

#[cfg(all($(not(target_os = $e)),*))]
fn imp(_meta: &fs::Metadata) -> Option<FileTime> {
None
}
}
#[cfg(target_os = "bitrig")]
{
use std::os::bitrig::fs::MetadataExt;
Some(FileTime {
seconds: meta.st_birthtime(),
nanos: meta.st_birthtime_nsec() as u32,
})
}

birthtim! {
("bitrig", bitrig),
("freebsd", freebsd),
("ios", ios),
("macos", macos),
("openbsd", openbsd)
#[cfg(not(target_os = "bitrig"))]
{
meta.created().map(|i| i.into()).ok()
}

imp(meta)
}