-
Notifications
You must be signed in to change notification settings - Fork 735
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
Fix #631 throw error when overwriting recently created file #702
Conversation
Codecov Report
@@ Coverage Diff @@
## master #702 +/- ##
==========================================
- Coverage 94.67% 94.66% -0.01%
==========================================
Files 33 33
Lines 1183 1219 +36
==========================================
+ Hits 1120 1154 +34
- Misses 63 65 +2
Continue to review full report at Codecov.
|
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.
@uttpal thanks for the PR! This looks good overall, but I think we're missing the case where we're copying a directory (with colliding contents).
I gave suggestions in the review comments. Let me know if I can clarify, or if I was mistaken about anything.
|
||
|
||
test('should not overwrite recently created files (in recursive Mode)', t => { | ||
const result = shell.cp('-R', 'resources/file1', 'resources/cp/file1', t.context.tmp); |
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.
Please add a test for copying a non-empty directory. How about this?
cp('-R', 'resources/cp/a', 'resources/cp/', t.context.tmp)
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.
Never mind, I don't think we need this test
@@ -150,6 +150,14 @@ function cpdirSyncRecursive(sourceDir, destDir, currentDepth, opts) { | |||
} // for files | |||
} // cpdirSyncRecursive | |||
|
|||
// Checks if cureent file was created recently | |||
function checkRecentCreated(sources, index) { |
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.
I think it's be better to keep a list of all copied files, as they're copied (instead of relying on the parameter list). The parameter list might contain directory names (but we actually want a list of all files inside those directories)
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.
@nfischer Thanks for suggestions.
How about we use the timestamp to check whether a file was created recently or not?
we can set a variable with current time when cp operation starts and then only overwrite files that were created before that.
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.
This sounds trickier--if someone is playing with timestamps on their files, we might get different behavior. The goal is to just catch files created by the current cp
command. I just suggested building a list of files we create, as we create them. Fairly confident this is how GNU cp
does this.
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.
It appears like relying on the parameter list is consistent with GNU cp
, I must have been mistaken when I tried it
test/mv.js
Outdated
|
||
result = shell.mv('t/file1', 'file1'); // revert | ||
t.truthy(fs.existsSync('file1')); | ||
t.truthy(fs.existsSync('cp/file1')); |
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.
Is this all to manually revert? I think our beforeEach step should be sufficient
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.
LGTM % this comment
Thanks! |
Fixes #631
If you have a copy command like:
$ cp file1.txt out/file1.txt destination/
You should get an error that says something like:
cp: will not overwrite just-created ‘destination/file1.txt’ with ‘out/file1.txt’
same behavior goes for mv with -R, -f flags.