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

feat: cp & mv should not overwrite recently created files #631

Labels
bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem help wanted low priority
Milestone

Comments

@nfischer
Copy link
Member

nfischer commented Dec 20, 2016

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’

We're currently silently overwriting files that we created in that same copy command, but should instead provide a warning and refuse to copy the second file.

The behavior should stay the same with -f and -r, but cp does not give the warning with directories or their contents.

$ cp dir1 out/dir1 destination/ # never has this error
$ ls destination/dir1/ # shows the merged contents of both ./dir1/ and out/dir1/

The warning is never present with the -n flag.

This warning should also be presented for the mv command.

@nfischer nfischer added bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem low priority labels Dec 20, 2016
@nfischer nfischer added this to the v0.7.x milestone Dec 20, 2016
@nfischer nfischer changed the title feat: cp should not overwrite recently created files feat: cp & mv should not overwrite recently created files Jan 9, 2017
@uttpal
Copy link
Contributor

uttpal commented Apr 7, 2017

@nfischer I would like to fix this issue.
Just for clarification, the Expected output is:

  1. -f and -r should provide warning and not overwrite the file.
  2. -n flag should not overwrite nor display the warning.

Please correct me if I am wrong.

@nfischer
Copy link
Member Author

@uttpal Help would be very appreciated!

Yes, I believe your understanding is correct. If in doubt, you can always try out GNU cp/mv on a Linux system.

@uttpal
Copy link
Contributor

uttpal commented Apr 14, 2017

@nfischer
In the case of a directory, cp is overwriting recently created files with the latest one.

cp -R dir1 dir2/dir1 dir3/dir1 dest/
cat dest/dir1/file1 > in dir3

@nfischer
Copy link
Member Author

In the case of a directory, cp is overwriting recently created files with the latest one.

You're right, I was mistaken. Thanks for double checking

uttpal added a commit to uttpal/shelljs that referenced this issue Apr 15, 2017
nfischer pushed a commit that referenced this issue Apr 15, 2017
* cp: add error to not overwrite recently created files #631

* cp: add tests for errors not overwrite recently created files #631

* mv: show error when overwriting recently created file #631

* mv: add tests for error on recently created files #631

* mv: test remove unnecessary steps #631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment