-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
cp: Updated prompt logic to handle update with and without interactive mode enabled #6069
Conversation
Can you please add a test to ensure we don't regress in the future? |
GNU testsuite comparison:
|
Hi @cakebaker, there was already a test case written for the current scenario. and for |
@Vikrant2691 all the better if there is already a test :) I don't know if you have seen that it fails? |
I will look into it today and let you know :)
…On Fri, Mar 15, 2024, 13:38 Daniel Hofstetter ***@***.***> wrote:
@Vikrant2691 <https://github.com/Vikrant2691> all the better if there is
already a test :) I don't know if you have seen that it fails?
—
Reply to this email directly, view it on GitHub
<#6069 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI3BNPRDWRUFSEQYMXP2PYLYYL2VVAVCNFSM6AAAAABEVDVBCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJZGY4DKNJXG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
GNU testsuite comparison:
|
GNU testsuite comparison:
|
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.
test_cp_arg_update_interactive
failed. Congratulations, this fix reveals the reason for a flaky test, because now it depends on which file is newer; and because the test fixture copies file in "random" order (typically inode order, which is "random"), this will fail 50% of the time.
Please fix this test; perhaps remove it entirely because this is now covered by the new tests.
Additional comments:
- I don't quite understand how
cp
is structured, and it seems surprising to me thathandle_existing_dest()
checks the update mode, even thoughhandle_copy_mode()
checks it again a bit later. Is there a scenario where it ends up asking for confirmation twice? - If you feel like writing more tests, I think it's a good idea to test
test_cp_arg_interactive_update_overwrite_older()
but with the inputY
. - Although this project seems to pay not much attention to it, I would like to recommend git rebase to you. This is a great opportunity to get started! In this case, maybe a single or perhaps two commits would be easier to understand than 11 fix-fixing-fix-commits and pointless merge-commits.
tests/by-util/test_cp.rs
Outdated
// -u -i *WILL* show the prompt to validate the override. | ||
// Therefore, the error code depends on the prompt response. | ||
let (at, mut ucmd) = at_and_ucmd!(); | ||
at.touch("b"); | ||
std::thread::sleep(Duration::from_secs(1)); |
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.
could you please add a comment why sleep ?
and can we make it shorter ?
thanks
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.
yes, this issue is what I posted in the chat. The test itself was failing initially. The reason is that the two create calls are so close to each other that the files get at the same time. To mitigate that we have two options. 1) add a delay and 2) set time explicitly.
I tried to set time explicitly initially, but the libraries I used were unstable (FileTimes). Please let me know if you have some option to set time while creating the file. I had no other option than to use 1.
Sorry, I did not get what you meant by shorter...
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.
For 2) you could use something like:
let _ = at.make_file("b").set_modified(std::time::SystemTime::UNIX_EPOCH);
Update: Please ignore it, I just realized this snippet requires Rust 1.75 :|
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.
For 2) you could use something like:
let _ = at.make_file("b").set_modified(std::time::SystemTime::UNIX_EPOCH);Update: Please ignore it, I just realized this snippet requires Rust 1.75 :|
yes, I tried FileTimes but it did not work as you said...
Actions on me:
Answering additional comments
|
I am not sure why the checks in the pipeline failed.. could we please run it again |
@Vikrant2691 The failure of the |
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.
Looks good to me!
EDIT: Looks like this needs a slightly more involved rebase. I currently don't have the capacity to do it, sorry. Your options are:
- Some other maintainer steps in and rebases it
- You rebase it (highly recommended!), and make it trivial to merge
- A long time passes, I have enough time, and then I'll rebase it.
okk let me check |
Could you please check if the rebase is successful? |
Sorry, my bad, let me try to fix this. |
I messed up, I didn't want to close this PR, and because of reasons that I understand but cannot fix, this PR cannot be re-opened easily. Instead, please see #6207. I promise to learn from my mistake! Please sanity-check whether this looks correct. git diff says there is no difference in content between c94809b (your original final commit) and 9b9c0cc (this commit). If you agree that there is no difference, I'll just merge #6207 instead. |
Okk let me check
…On Tue, Apr 9, 2024, 14:31 Ben Wiederhake ***@***.***> wrote:
I messed up, I didn't want to close this PR, and because of reasons that I
understand but cannot fix, this PR cannot be re-opened easily. Instead,
please see #6207 <#6207>. I
promise to learn from my mistake!
Please sanity-check whether this looks correct. git diff says there is no
difference in content between c94809b
<c94809b>
(your original final commit) and 9b9c0cc
<9b9c0cc>
(this commit).
If you agree that there is no difference, I'll just merge #6207
<#6207> instead.
—
Reply to this email directly, view it on GitHub
<#6069 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AI3BNPTKEX6G3EXSTCATUU3Y4PUSXAVCNFSM6AAAAABEVDVBCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBVGE4DONJUHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Fixes #6019
The issue was that the condition preemptively returned
Ok
when the status wasUpdateMode::ReplaceIfOlder
.But if the condition is removed, it will prompt for
coreutils cp -i -u old new
.This is a very peculiar condition where we don't want to prompt where we know time(old)>time(new). (update only overwrites when a new file is copied to an old file.)
So, the prompt needs to be closer to the condition where the time for the folders is checked.