Skip to content

fix for platform inconsistency in creation time #17272

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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion src/libnative/io/file_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,29 @@ fn mkstat(stat: &libc::stat) -> rtio::FileStat {
#[cfg(target_os = "linux")] #[cfg(target_os = "android")]
fn gen(_stat: &libc::stat) -> u64 { 0 }

#[cfg(target_os = "linux")]
fn created(_stat: &libc::stat) -> u64 { 0 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @thestinger, surely linux supports this via some means.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the debugfs utility wrestles it out somehow:
http://tecadmin.net/file-creation-time-linux/

We might be able to somehow do this programatically, but it definitely, according to my research, does not come for free. Perhaps that should be a separate PR?

#[cfg(target_os = "windows")]
fn created(stat: &libc::stat) -> u64 { mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64) }
#[cfg(target_os = "macos", target_arch = "x86_64")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this for only 64-bit OSX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/stat.2.html

If you look at the second struct stipulated (the one that contains birthtime), it mentions that that structure is only defined that way when the macro _DARWIN_FEATURE_64_BIT_INODE is defined. Unless 32 bit systems can have this macro defined?

fn created(stat: &libc::stat) -> u64 {
mktime(stat.st_birthtime as u64, stat.st_birthtime_nsec as u64)
}
#[cfg(target_os = "freebsd")]
fn created(stat: &libc::stat) -> u64 {
mktime(stat.st_birthtime as u64, stat.st_birthtime_nsec as u64)
}
#[cfg(target_family = "unix")]
fn changed(stat: &libc::stat) -> u64 { mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64) }
#[cfg(target_os = "windows")]
fn changed(_stat: &libc::stat) -> u64 { 0 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this field should be added just yet because windows doesn't support it and the structure of FileStat is that the top levels are "officially supported"


rtio::FileStat {
size: stat.st_size as u64,
kind: stat.st_mode as u64,
perm: stat.st_mode as u64,
created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64),
created: created(stat),
changed: changed(stat),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a "changed" field in the FileStat structure, does this compile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wups, will fix.

modified: mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64),
accessed: mktime(stat.st_atime as u64, stat.st_atime_nsec as u64),
device: stat.st_dev as u64,
Expand Down
1 change: 1 addition & 0 deletions src/librustrt/rtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ pub struct FileStat {
pub kind: u64,
pub perm: u64,
pub created: u64,
pub changed: u64,
pub modified: u64,
pub accessed: u64,
pub device: u64,
Expand Down
1 change: 1 addition & 0 deletions src/librustuv/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl FsRequest {
kind: stat.st_mode as u64,
perm: stat.st_mode as u64,
created: to_msec(stat.st_birthtim),
changed: to_msec(stat.st_ctim),
modified: to_msec(stat.st_mtim),
accessed: to_msec(stat.st_atim),
device: stat.st_dev as u64,
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn from_rtio(s: rtio::FileStat) -> FileStat {
type Mode = libc::mode_t;

let rtio::FileStat {
size, kind, perm, created, modified,
size, kind, perm, created, changed, modified,
accessed, device, inode, rdev,
nlink, uid, gid, blksize, blocks, flags, gen
} = s;
Expand All @@ -391,6 +391,7 @@ fn from_rtio(s: rtio::FileStat) -> FileStat {
},
perm: FilePermission::from_bits_truncate(perm as u32),
created: created,
changed: changed,
modified: modified,
accessed: accessed,
unstable: UnstableFileStat {
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,9 @@ pub struct FileStat {
/// The time that the file was created at, in platform-dependent
/// milliseconds
pub created: u64,
/// The time that the file was changed (in metadata or content)
/// in platform-dependent milliseconds
pub changed: u64,
/// The time that this file was last modified, in platform-dependent
/// milliseconds
pub modified: u64,
Expand Down