coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

du: support arbitrary time formats

Open Qelxiros opened this issue 9 months ago • 8 comments

closes #7665

Most of the logic was already here, but there was a premature check that raised an error.

Qelxiros avatar Apr 08 '25 02:04 Qelxiros

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Apr 08 '25 02:04 github-actions[bot]

@tertsdiepraam I added a regex-based solution to escape invalid sequences, but it's unfortunately slow. It's linear time if the format string is valid, but potentially quadratic time if the format string is designed against this approach. I opened chronotope/chrono#1692 to potentially add GNU's functionality into chrono directly. Without that, I don't see a better solution than either panicking or using a regex. If you want me to revert df13534 in favor of performance, let me know.

Note: there is a third option in which we use the regex for validation, but error if it matches the input string.

Qelxiros avatar Apr 09 '25 02:04 Qelxiros

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

github-actions[bot] avatar Apr 09 '25 03:04 github-actions[bot]

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

github-actions[bot] avatar Apr 11 '25 02:04 github-actions[bot]

Update: My PR to chrono has been merged, so we'll be able to use that implementation when they update to 0.4.41.

Qelxiros avatar Apr 11 '25 07:04 Qelxiros

That's definitely a pretty clever solution, but that regex feels very complicated to me. We might ultimately just need to build our own formatting, like in https://github.com/uutils/coreutils/pull/7255. Maybe a "safer" (but not more correct) temporary solution is to use parse like chrono's maintainer suggested? Or implement our own iterator copied from that PR?

As a sidenote, please do not open issues on behalf of uutils on crates without discussing with us. I'm worried that maintainers of crates like chrono and clap might get annoyed with our project if that happens too often. The maintainers of uutils often have more knowledge about the history of interaction with other maintainres. Great job on getting it merged though! We should definitely switch to that when we can.

tertsdiepraam avatar Apr 17 '25 21:04 tertsdiepraam

I agree that the regex is quite complicated. It wasn't a completely serious suggestion, but I got distracted by the possibility and then was pleased by the results. Is #7255 in a state to be worked on or are there blockers there that I don't know about? Is the provided list of differences from chrono strftime exhaustive? As for this PR, should I wait for changes from #7255 or switch to chrono's StrftimeItems::parse and error gracefully?

Sorry about the PR; I wasn't aware of the situation. Thanks for the feedback!

Qelxiros avatar Apr 18 '25 01:04 Qelxiros

This PR is fine too have next to #7255! #7255 is very big so might take a while to land. Looks like it's barely reviewed yet (and not at all by me so I don't really know what the state of it is).

Your changes can probably be merged soon, so let's just do that first.

tertsdiepraam avatar Apr 18 '25 07:04 tertsdiepraam