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

rm: Added descend messages for interactive mode Fixes #3817 #3931

Merged
merged 10 commits into from
Oct 5, 2022
Merged

rm: Added descend messages for interactive mode Fixes #3817 #3931

merged 10 commits into from
Oct 5, 2022

Conversation

palaster
Copy link
Contributor

Added descend functionality for rm's interactive mode

Setup

mkdir -p a/b/
touch a/at.txt a/b/bt.txt
rm -ri a

Current

rm: remove file 'test/a/b/bt.txt'? y
rm: remove file 'test/a/at.txt'? y
rm: remove directory 'test/a/b'? y
rm: remove directory 'test/a'? y

GNU

rm: descend into directory 'a'? y
rm: descend into directory 'a/b'? y
rm: remove regular empty file 'a/b/bt.txt'? y
rm: remove directory 'a/b'? y
rm: remove regular empty file 'a/at.txt'? y
rm: remove directory 'a'? y

After Commit (Using the same answers as before)

rm: descend into directory 'test/a'? y
rm: descend into directory 'test/a/b'? y
rm: remove file 'test/a/b/bt.txt'? y
rm: remove file 'test/a/at.txt'? y
rm: remove directory 'test/a/b'? y
rm: remove directory 'test/a'? y

After Commit (Don't descend into a/b)

rm: descend into directory 'test/a'? y
rm: descend into directory 'test/a/b'? n
rm: remove file 'test/a/at.txt'? y
rm: remove directory 'test/a'? y
./uutils/target/debug/rm: cannot remove 'test/a': Directory not empty

@tertsdiepraam tertsdiepraam linked an issue Sep 14, 2022 that may be closed by this pull request
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.

Cool! Looks like WalkDir is becoming a bit of a hassle to work around, but this looks like a good way to do this for now. Could you add a test to check that we don't regress?

@sylvestre
Copy link
Contributor

it would be nice if you could make GNU's test rm3.sh & rm5.sh work as they are also testing the
"descend into directory" thing.

bash util/run-gnu-test.sh tests/rm/rm3.sh
and
bash util/run-gnu-test.sh tests/rm/rm5.sh

@palaster
Copy link
Contributor Author

For making a regression test do you guys know/have an example test where you interact with the child process stdout and stdin?
Progress report for the test:
I looked at rm3.sh and will have to look deeper and see what it is doing
For rm5.sh I should be able to fix it. It is currently failing because GNU doesn't ask to descend if the directory is empty

@palaster
Copy link
Contributor Author

Just looked at rm3.sh and it seems to only be falling because our prompts aren't as descriptive as gnu.
For example GNU for an empty file with prompt:
rm: remove regular empty file 'z/empty'
While ours is just:
rm: remove file 'z/empty'
I might make that into a separate PR to give our prompts better descriptions

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Sep 15, 2022

For making a regression test do you guys know/have an example test where you interact with the child process stdout and stdin?

Would the pipe_in method work? Here's an example:

https://github.com/uutils/coreutils/blob/main/tests/by-util/test_cp.rs#L199-L208

I might make that into a separate PR to give our prompts better descriptions.

Yeah a separate PR makes sense I think.

@palaster
Copy link
Contributor Author

palaster commented Sep 15, 2022

Unfortunately, that won't work for this use case where the command waits for responses and does something different depending on it. I am currently looking at just using a bare Child and then reading and writing to its stdin and stdout... but that is proving challenging.

@palaster
Copy link
Contributor Author

Okay, I have created a very basic test for checking directory descending.

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 like it! We can merge this once the CI succeeds and my nits below are addressed.

tests/by-util/test_rm.rs Outdated Show resolved Hide resolved
src/uu/rm/src/rm.rs Show resolved Hide resolved
@tertsdiepraam
Copy link
Member

There seems to be some trouble on macos and windows:

test test_rm::test_rm_descend_directory has been running for over 60 seconds

@palaster
Copy link
Contributor Author

palaster commented Oct 1, 2022

So, the reason it was hanging up is because of CRLF vs LF when I was inserting it into stdin. I also had to remake the test because of something I noticed with WalkDir that depending on the system the order in which it traverses can differ. Everything seems to be working now


let mut child: Child = scene.ucmd().arg("-ri").arg("a").run_no_wait();

let mut child_stdin = child.stdin.take().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

please document why it is needed

if options.interactive == InteractiveMode::Always {
for not_descend in &not_descended {
if entry.path().starts_with(not_descend) {
continue 'outer;
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment explaining why we do that here

} else {
not_descended.push(entry.path().to_path_buf());
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

please add a comment here. it is starting to be quite complex with the various if and else

Copy link
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

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

misses some comments

@palaster palaster requested a review from sylvestre October 4, 2022 20:10
@sylvestre
Copy link
Contributor

Nice
Congrats! The gnu test tests/rm/rm5 is no longer failing!

@sylvestre sylvestre merged commit 493a262 into uutils:main Oct 5, 2022
@palaster palaster deleted the r-i-descend branch October 5, 2022 18:47
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.

rm descend into directory at interactive mode missing
3 participants