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

The "ctime" field from stat is not time of file creation. #15168

Closed
zookoatleastauthoritycom opened this Issue Jun 25, 2014 · 8 comments

Comments

Projects
None yet
6 participants
@zookoatleastauthoritycom
Copy link

zookoatleastauthoritycom commented Jun 25, 2014

fn from_rtio(s: rtio::FileStat) -> FileStat {
seems to be reading the 4th field of stat result and storing it as "created", but if that 4th field is coming from stat_ctime then this is a bug, because stat_ctime is not the time of file creation, but is instead the most recent time that either the content or the metadata of the file changed: https://en.wikipedia.org/wiki/Stat_%28Unix%29#ctime

@alexcrichton alexcrichton added A-iOS and removed A-iOS labels Jun 28, 2014

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jun 28, 2014

Indeed! Looks like we need to switch to birthtime where necessary

@alexcrichton alexcrichton added the E-easy label Jun 28, 2014

@pdovy

This comment has been minimized.

Copy link

pdovy commented Jul 8, 2014

I took a look at this as it seemed like possibly an easy first issue. On Windows, st_ctime is indeed the file creation time - so on that platform the current implementation is correct. On Unix platforms it is wrong as mentioned, but the birthtime field mentioned by @alexcrichton doesn't seem to exist outside of BSD - it's not a standard part of POSIX.

Do we have any ability to have platform-dependent code in src/libnative/io/file_unix.rs?

It seems like the right approach may be to have an additional field on FileStat to hold the status change timestamp, which would be zero on Windows and hold the st_ctime value on Unix, and (possibly excepting BSD) the existing created field would be zero on Unix since it's unavailable.

@omasanori

This comment has been minimized.

Copy link
Contributor

omasanori commented Jul 20, 2014

FYI:
Ruby's birthtime discussion (in Japanese; let me know if you need a summary in English)
Commits adding File#birthtime and File.birthtime to Ruby ruby/ruby@6b4f921 ruby/ruby@bfa4f32

@thestinger

This comment has been minimized.

Copy link
Contributor

thestinger commented Jul 20, 2014

OS X and *BSD do have the ability to get creation time via stat. It's also possible on Linux for some file systems too.

@salemtalha

This comment has been minimized.

Copy link
Contributor

salemtalha commented Sep 14, 2014

@thestinger just experimented on ext4 and neither crtime nor btime are returned by the stat systemcall. maybe there's some other syscall that will expose that variable. investigating..

@omasanori

This comment has been minimized.

Copy link
Contributor

omasanori commented Sep 14, 2014

On Linux, you can get creation time via debugfs if you are root. AFAIK (and, according to the Ruby's discussion linked from my previous comment,) there is no way to get it on Linux via any system call for now.

@salemtalha

This comment has been minimized.

Copy link
Contributor

salemtalha commented Sep 15, 2014

i took a preliminary stab at it in #17272, could someone let me know if I'm on the right track?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 11, 2015

This was handled in the new std::fs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.