-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
du
/ls
: Improve time-style handling based on GNU coreutils manual
#8415
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
Conversation
From GNU manual, if LC_TIME=POSIX, then the "locale" timestamp is used. Else, `posix-` is stripped and the format is parsed as usual. Also, just move the whole text to the locale file, instead of trying to generate it manually.
According to GNU manual.
Documented in GNU manual. Also improve test_ls to test for both recent and older files.
ls has different time format for recent (< 6 months) and older files. Files in the future (even by just a second), are considered old, which makes sense as we probably want the date to be printed in that case.
Also add to error text, which... GNU coreutils doesn't do for some reason.
Along the way: - Fix the full-iso format, that was supposed to use %N, not %f (%f padded with chrono, but not with jiff, and %N is more correct and what GNU says in their manual) - The Hashmap thing in parse_time_style was too smart, to a point that it became too unflexible (it would have been even worse when we added locale support). I was hoping the share more of the code, but that seems difficult.
Similar as what ls does, but du has an extra compatibility layer described in the GNU manual (and that upstream dev helped me understand: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79113 ).
GNU testsuite comparison:
|
They were a bit jumbled with no particular logic, at least that I could see.
GNU testsuite comparison:
|
Sigh, looks like I broke GNU tests? Will look. |
…g.sh We now are closer to what GNU prints, and handle the [posix-] cases that they do.
This is fine,
I'd rather have a failing test than an incorrectly skipped test, we can fix it later.
|
GNU testsuite comparison:
|
"iso" => Ok("%Y-%m-%d"), | ||
_ => Err(DuError::InvalidTimeStyleArg(s.into()).into()), | ||
Some(s) => match s.as_ref() { | ||
"full-iso" => Ok(format::FULL_ISO.to_string()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to use an enum here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confused in Rust.... How? ,-P
This is not allowed (you can set values but they need to be isize
type:
enum Format {
FULL_ISO = "%Y-%m-%d %H:%M:%S.%N %z",
LONG_ISO = "%Y-%m-%d %H:%M",
ISO = "%Y-%m-%d",
}
https://stackoverflow.com/questions/36928569/how-can-i-create-enums-with-constant-values-in-rust gave me this idea:
pub struct Format;
impl Format {
pub const FULL_ISO: &str = "%Y-%m-%d %H:%M:%S.%N %z";
pub const LONG_ISO: &str = "%Y-%m-%d %H:%M";
pub const ISO: &str = "%Y-%m-%d";
}
This is not so bad (I somewhat prefer using static
to const
but that's not allowed here... but maybe I'm wrong, I think static
and const
should behave the same anyway in this case)
---- wait---
Or you mean something like:
enum Format {
LongIso,
FullIso,
Iso,
Custom(String)
}
That's not awesome. Would work ok in the du
case, but really not in the ls
case that has quite a bit more logic (and it's probably better performance-wise to collect the String
format first and not do more checks at formatting time).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, enum Format {
but please ignore me if it doesn't make sense!
This fixes #7665, and generally bring
du
/ls
time-style
to feature parity with GNU (at least AFAICT...) -- apart from localization.I was hoping the share more of the code between
du
andls
, but that seems difficult as the options and parsing is actually different. But at least we can share constants.Some
pr
fixes will follow in another MR (that one only support specific FORMAT).util/build-gnu.sh: Change string matching for tests/ls/time-style-diag.sh
We now are closer to what GNU prints, and handle the [posix-] cases
that they do.
ls: cleanup imports
They were a bit jumbled with no particular logic, at least that
I could see.
ls: Fix Windows build
du: Add support for reading time-style from environment
Similar as what ls does, but du has an extra compatibility layer
described in the GNU manual (and that upstream dev helped me
understand: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79113 ).
du/ls: Move common time formats to constants in uucore/time
Along the way:
(%f padded with chrono, but not with jiff, and %N is more correct
and what GNU says in their manual)
that it became too unflexible (it would have been even worse
when we added locale support).
I was hoping the share more of the code, but that seems difficult.
du: Add support for +FORMAT time-style
Also add to error text, which... GNU coreutils doesn't do for
some reason.
ls: Print dates in the future as "old" ones
ls has different time format for recent (< 6 months) and older files.
Files in the future (even by just a second), are considered old,
which makes sense as we probably want the date to be printed in
that case.
ls: Add support for newline separated format for recent/older
Documented in GNU manual.
Also improve test_ls to test for both recent and older files.
ls: Allow reading time-style from TIME_STYLE environment variable
According to GNU manual.
ls: Add support for --time-style=posix-*
From GNU manual, if LC_TIME=POSIX, then the "locale" timestamp is
used. Else,
posix-
is stripped and the format is parsed as usual.Also, just move the whole text to the locale file, instead
of trying to generate it manually.