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

Support ls --dired #5280

Merged
merged 11 commits into from
Sep 20, 2023
Merged

Support ls --dired #5280

merged 11 commits into from
Sep 20, 2023

Conversation

sylvestre
Copy link
Contributor

No description provided.

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!

@sylvestre sylvestre requested review from tertsdiepraam and cakebaker and removed request for tertsdiepraam September 16, 2023 18:52
Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already much cleaner than when I looked at it this morning. However, I still think there's a lot of ways this could break and there seem to be a lot of ``moving parts'', if that makes sense. For example, some calculation might break if we change the output slightly.

Have you tried my suggestion of a wrapper around a writer that counts the number of bytes printed? I think that has several advantages:

  • we don't need to store a string
  • we don't need to lookup the last item on positions
  • we don't need to do any manual calculations
  • we can ignore total (because we don't need the string anymore)

It feels to me like a more natural way of dealing with this. What do you think?

src/uu/ls/src/ls.rs Outdated Show resolved Hide resolved
src/uu/ls/src/ls.rs Outdated Show resolved Hide resolved
src/uu/ls/src/ls.rs Outdated Show resolved Hide resolved
src/uu/ls/src/dired.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!
Congrats! The gnu test tests/ls/stat-failed is no longer failing!

@sylvestre
Copy link
Contributor Author

 It feels to me like a more natural way of dealing with this. What do you think?

That perfect is the enemy of the good :)
It works and it fixes 2 gnu tests.
I could open a good first bug if someone is motivated to fix it in the future

@tertsdiepraam
Copy link
Member

Alright!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!
Congrats! The gnu test tests/ls/stat-failed is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!
Congrats! The gnu test tests/ls/stat-failed is no longer failing!

Comment on lines +3527 to +3536
fn test_ls_dired_incompatible() {
let scene = TestScenario::new(util_name!());

scene
.ucmd()
.arg("--dired")
.fails()
.code_is(1)
.stderr_contains("--dired requires --format=long");
}
Copy link
Contributor

@cakebaker cakebaker Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test seems to be incorrect. At least with GNU ls 9.3, running ls --dired doesn't fail. It simply ignores the --dired option and outputs the same as ls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it is a GNU issue. I will fix it there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let result = cmd.succeeds();
// Number of blocks
#[cfg(target_os = "linux")]
result.stdout_contains(" total 4");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason this line fails on my machine because the total is 0 :| It works fine, and the total is 4, if I do the steps manually...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and you run linux ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I'm running Arch Linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the debug output:

Output:
  total 0
  -rw-r--r-- 1 dho dho    0 Sep 18 08:00 a1
  -rw-r--r-- 1 dho dho    0 Sep 18 08:00 a22
  -rw-r--r-- 1 dho dho    0 Sep 18 08:00 a333
  -rw-r--r-- 1 dho dho    0 Sep 18 08:00 a4444
  drwxr-xr-x 2 dho dho   40 Sep 18 08:00 d
//DIRED// 51 53 95 98 140 144 186 191 233 234
//DIRED-OPTIONS// --quoting-style=literal

The two odd things are the timestamps (they're off by two hours) and the size of the directory (it's 40 instead of 4096)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun!
as you know, it isn't the fault of this PR :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I added it to my todo list to investigate further

tests/by-util/test_ls.rs Outdated Show resolved Hide resolved
sylvestre and others added 2 commits September 18, 2023 11:10
Co-authored-by: Daniel Hofstetter <[email protected]>
Co-authored-by: Daniel Hofstetter <[email protected]>
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!
Congrats! The gnu test tests/ls/stat-failed is no longer failing!

/// Calculates the byte positions for DIRED
pub fn calculate_dired_byte_positions(
output_display_len: usize,
dfn_len: usize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does dfn mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Display File Name

we should rename it (it is from ls.rs)
I will create an issue

src/uu/ls/src/ls.rs Outdated Show resolved Hide resolved
Co-authored-by: Daniel Hofstetter <[email protected]>
src/uu/ls/src/dired.rs Outdated Show resolved Hide resolved
pub struct DiredOutput {
pub dired_positions: Vec<BytePosition>,
pub subdired_positions: Vec<BytePosition>,
pub just_printed_total: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling with this field, it somehow doesn't fit to the other fields because it doesn't contain any data like the other fields. Though I don't know where it should be instead :|

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, i used to have it in BytePosition but terts didn't like it and suggested this place :)

However, I would not overthink this, this feature is probably not used much and won't get many updates

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!
Congrats! The gnu test tests/ls/stat-failed is no longer failing!

Copy link
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the fmt issue is fixed I think it is ready to be merged.

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/dired is no longer failing!
Congrats! The gnu test tests/ls/stat-failed is no longer failing!

@cakebaker cakebaker merged commit 9b4d2c6 into uutils:main Sep 20, 2023
44 of 47 checks passed
@sylvestre sylvestre deleted the perm branch September 28, 2023 11:05
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.

3 participants