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

Don't make assumptions about Metadata based on temp_dir #622

Closed
wants to merge 1 commit into from

Conversation

mrkline
Copy link

@mrkline mrkline commented Jan 13, 2020

Previously, exa would attempt to get the metadata for
std::env::temp_dir, and if fetching a certain timestamp
(e.g., creation time) failed, it would assume that the OS couldn't
produce that stamp for any file. Requests to display or sort by that
timestamp would misfire the entire program.

This caused exa to make some sweeping claims that aren't true; e.g., that
Linux can't produce file creation times. The real story is that tmpfs
(the filesystem usually used for /tmp) can't, but other Linux
filesystems can and do. (The Rust standard library docs even mention
that Metadata.created() is backed by statx() since Linux 4.11.)

Since exa could be asked to list files from several filesystems,
let's handle metadata on a per-file basis. This patch makes File's
*_time() methods return an Option
(changed_time() always returns None on a non-Unix system),
and prints a hyphen for files without that particular timestamp.
For example:

    $ exa -lhUd --sort=created /tmp/example Cargo.toml Cargo.lock src target

    Permissions Size User    Date Created Name
    .rw-r--r--     0 mrkline -            /tmp/example
    .rw-r--r--   25k mrkline 12 Jan 22:35 Cargo.lock
    .rw-r--r--  1.2k mrkline 12 Jan 22:35 Cargo.toml
    drwxr-xr-x     - mrkline 12 Jan 22:35 src
    drwxr-xr-x     - mrkline 12 Jan 22:46 target

@mrkline mrkline force-pushed the per-file-dates branch 2 times, most recently from 55ef458 to 1258de3 Compare January 13, 2020 07:43
Previously, exa would attempt to get the metadata for
`std::env::temp_dir`, and if fetching a certain timestamp
(e.g., creation time) failed, it would assume that the OS couldn't
produce that stamp for _any_ file. Requests to display or sort by that
timestamp would misfire the entire program.

This caused exa to make some sweeping claims that aren't true; e.g., that
Linux can't produce file creation times. The real story is that tmpfs
(the filesystem usually used for `/tmp`) can't, but other Linux
filesystems can and do. (The Rust standard library docs even mention
that `Metadata.created()` is backed by `statx()` since Linux 4.11.)

Since exa could be asked to list files from several filesystems,
let's handle metadata on a per-file basis. This patch makes File's
`*_time()` methods return an Option<Duration>
(`changed_time()` always returns None on a non-Unix system),
and prints a hyphen for files without that particular timestamp.
For example:

    $ exa -lhUd --sort=created /tmp/example Cargo.toml Cargo.lock src target

    Permissions Size User    Date Created Name
    .rw-r--r--     0 mrkline -            /tmp/example
    .rw-r--r--   25k mrkline 12 Jan 22:35 Cargo.lock
    .rw-r--r--  1.2k mrkline 12 Jan 22:35 Cargo.toml
    drwxr-xr-x     - mrkline 12 Jan 22:35 src
    drwxr-xr-x     - mrkline 12 Jan 22:46 target
@mrkline
Copy link
Author

mrkline commented Jan 13, 2020

Ah, apparently using statx() in the standard library is relatively new: rust-lang/rust#65094

@ogham
Copy link
Owner

ogham commented Jan 19, 2020

Thanks for your contribution, and for pointing me towards statx — it's been a while since I looked at the stat manual page and that function was new to me.

In this case, I merged another PR that took care of the temp_dir call, so I'm afraid I can't merge this one.

@ogham ogham closed this Jan 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants