Fix #631 throw error when overwriting recently created file#702
Fix #631 throw error when overwriting recently created file#702nfischer merged 5 commits intoshelljs:masterfrom
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.
|
nfischer
left a comment
There was a problem hiding this comment.
@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.
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.
Never mind, I don't think we need this test
| } // cpdirSyncRecursive | ||
|
|
||
| // Checks if cureent file was created recently | ||
| function checkRecentCreated(sources, index) { |
There was a problem hiding this comment.
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.
@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.
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.
It appears like relying on the parameter list is consistent with GNU cp, I must have been mistaken when I tried it
|
|
||
| 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.
Is this all to manually revert? I think our beforeEach step should be sufficient
|
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.