Sitelet https://web.archive.org/web/20201123153810/https://github.com/shelljs/shelljs/issues/631
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

Comments

@nfischer
Copy link
Member

@nfischer 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 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 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

@nfischer nfischer commented Apr 10, 2017

@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 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

@nfischer nfischer commented Apr 15, 2017

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 added 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
You can’t perform that action at this time.