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

dd: allow skipping and seeking in FIFOs #4164

Merged
merged 3 commits into from
Feb 22, 2023

Conversation

jfinkels
Copy link
Collaborator

@jfinkels jfinkels commented Nov 19, 2022

First, this pull request creates a Source enum and simplifies the Input struct in dd, mirroring pull request #4134 that introduced the Dest enum and a simplified Output struct. Second, this pull request adds support seeking in FIFOs given as either input or output (or both). For example, dd seek=1 of=fifo and dd skip=1 if=fifo will now work.

This should cause GNU test suite file tests/dd/no-allocate.sh to change from ERROR to FAIL status.

Fixes #3321.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@jfinkels
Copy link
Collaborator Author

Well, there's a few platform-compatibility issues I'll need to work out, but this is good news:

Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

3 similar comments
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

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.

Love where this is going!

src/uu/dd/src/dd.rs Outdated Show resolved Hide resolved
@jfinkels
Copy link
Collaborator Author

Looks like something is not working right on macos:

2022-11-20T20:44:52.4512090Z test test_dd::test_seek_output_fifo has been running for over 60 seconds
2022-11-20T20:44:53.4303380Z test test_dd::test_skip_input_fifo has been running for over 60 seconds

What do you think about just skipping those two tests on macos and opening a new issue requesting an implementation that works on macos? I don't have a Mac computer so it's hard for me to debug these issues.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

src/uu/dd/src/dd.rs Outdated Show resolved Hide resolved
.succeeds()
.stderr_only("0+0 records in\n0+0 records out\n");

let output = child.wait_with_output().unwrap();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If pull request #4136 gets merged, that would allow me to make these tests more concise.

Copy link
Member

Choose a reason for hiding this comment

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

That PR is now merged, do you still want to do this in this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I was wrong when I made this comment. The child process comes from Command, not UCommand, so I don't think any changes can be made here at the moment.

Copy link
Member

@tertsdiepraam tertsdiepraam Dec 13, 2022

Choose a reason for hiding this comment

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

You could use ts.cmd("dd") to make it a UCommand (which will still call the system dd, not uutils), but it's not a high priority.

@jfinkels
Copy link
Collaborator Author

I tried getting the macos build to succeed using @tertsdiepraam's suggestion, but it doesn't seem to work.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

github-actions bot commented Dec 2, 2022

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

github-actions bot commented Dec 4, 2022

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

github-actions bot commented Dec 4, 2022

GNU testsuite comparison:

Congrats! The gnu test tests/tail-2/inotify-dir-recreate is no longer failing!
GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

github-actions bot commented Dec 6, 2022

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@github-actions
Copy link

github-actions bot commented Dec 6, 2022

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

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 the dd_out should also just become a free function dd, but that's not high priority. This cleans up so much already.

.succeeds()
.stderr_only("0+0 records in\n0+0 records out\n");

let output = child.wait_with_output().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

That PR is now merged, do you still want to do this in this PR?

@jfinkels
Copy link
Collaborator Author

jfinkels commented Dec 7, 2022

I think the dd_out should also just become a free function dd, but that's not high priority.

Great minds think alike; I have such a branch on my local machine but it depends on this branch, so I was waiting until this is merged.

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

@jfinkels
Copy link
Collaborator Author

jfinkels commented Dec 8, 2022

I skipped the tests for this feature on macos and freebsd because I wasn't sure how to make the implementation work.

This mirrors a recent commit that introduced the `Dest` enum and a
simplified `Output` struct. These changes allow us to add new types of
inputs and output more easily.
For example, `dd seek=1 of=fifo` will now work.
For example, `dd skip=1 if=fifo` will now work.
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/dd/no-allocate. tests/dd/no-allocate is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/rm/rm2. tests/rm/rm2 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail-2/inotify-dir-recreate. tests/tail-2/inotify-dir-recreate is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/dd/no-allocate is no longer ERROR!

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.

Excellent! Just one nit

Comment on lines +191 to +193
if settings.skip > 0 {
src.skip(settings.skip)?;
}
Copy link
Member

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 extract this? It appears in all the new_* functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean to factor these three lines out of the new_* functions into a new helper function and call that function in each of the three places? If so, I don't think it offers much benefit but I can do that if you it seems better to you.

Or do you mean to move this functionality out to the calling code so that it appears after the call to new_*()? I think I tried a design like that when I was first working on this pull request, but I no longer remember if it worked :).

Copy link
Member

@tertsdiepraam tertsdiepraam Feb 22, 2023

Choose a reason for hiding this comment

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

Or do you mean to move this functionality out to the calling code so that it appears after the call to new_*()?

I meant this one, but it's not that important. Let's just merge this :)

@tertsdiepraam tertsdiepraam merged commit 60d2df5 into uutils:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dd: seek should cause a read from named pipe but doesn't
2 participants