Closed Bug 1660841 Opened 5 years ago Closed 5 years ago

Allow querying file creation time in nsIFile

Categories

(Core :: XPCOM, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
85 Branch
Tracking Status
firefox85 --- fixed

People

(Reporter: mail, Assigned: beth)

References

Details

Attachments

(1 file)

It would be very useful to be able to query file creation time from the nsIFile interface.

This could be made available by a new method like nsresult nsIFile::GetCreationTime(PRTime aCreatedAt&).

  • On Windows, this information is provided via the GetFileTime syscall.

  • On macOS, this information is provided by the st_birthtimespec field of the struct returned by stat (2).

  • On Linux (including Android), while most file systems do store the creation time, it is not accessible from any standard syscall. On these platforms we could just return NS_NOT_AVAILABLE from the implementation.

Blocks: 1660843

For Linux can't we use statx? Per https://man7.org/linux/man-pages/man2/statx.2.html the struct contains struct statx_timestamp stx_btime; /* Creation */. I think the main problem might be that there is no libc API for this.

(In reply to Tom Schuster [:evilpie] from comment #1)

For Linux can't we use statx? Per https://man7.org/linux/man-pages/man2/statx.2.html the struct contains struct statx_timestamp stx_btime; /* Creation */. I think the main problem might be that there is no libc API for this.

Rust to the rescue! https://github.com/rust-lang/rust/blob/ffd59bf9c62125813abae8ca52f0ac3a67459e8f/library/std/src/sys/unix/fs.rs#L91

Assignee: nobody → brennie

We don't support statx in our sandbox yet (see https://bugzilla.mozilla.org/show_bug.cgi?id=1673771). It also won't work on older kernels I guess. So be prepared to handle ENOSYS on Linux.

Attachment #9187459 - Attachment description: Bug 1660841 - Provide file creation time via nsIFile::creationTime{,ofLink} on Mac, Windows r?nika → Bug 1660841 - Provide file creation time via nsIFile::creationTime{,ofLink} r?nika
Pushed by brennie@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/12448bfd676b Provide file creation time via nsIFile::creationTime{,ofLink} r=nika
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 85 Branch
Regressions: 1742928
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: