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

Data loss. shell.cp() Content of file is erased when trying to copy it to the folder it already belongs to #1092

Open
luiszun opened this issue Apr 30, 2022 · 4 comments
Labels
bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem medium priority

Comments

@luiszun
Copy link

luiszun commented Apr 30, 2022

Node version (or tell us if you're using electron or some other framework): v10.19.0

ShellJS version (the most recent version/Github branch you see the bug on): 0.8.3

Operating system: Linux (Ubuntu 20.04)

Description of the bug:

Regression from issue #678

Copying a directory to its same location causes the content of the files to be wiped out.

Example ShellJS command to reproduce the error:

shell.cp('-R','/home/luiszun/srcdir', '/home/luiszun');

Here's mi bash history with a repro and some info

luiszun@luiszun-box:~/tmp/test$ cat ~/srcdir/lol
deadbeef
luiszun@luiszun-box:~/tmp/test$ cat script
var shell = require('shelljs');

shell.cp('-r','/home/luiszun/srcdir/.', '/home/luiszun/');
luiszun@luiszun-box:~/tmp/test$ nodejs script
luiszun@luiszun-box:~/tmp/test$ cat ~/srcdir/lol
luiszun@luiszun-box:~/tmp/test$ npm list
/home/luiszun/tmp/test
└── (empty)

luiszun@luiszun-box:~/tmp/test$ npm list -g
/usr/local/lib
└── (empty)

luiszun@luiszun-box:~/tmp/test$ apt list | grep shellj

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

node-shelljs/focal,now 0.8.3-1 all [installed]
luiszun@luiszun-box:~/tmp/test$
@nfischer
Copy link
Member

nfischer commented May 1, 2022

Since this seems to be a regression, can you try the same code on earlier ShellJS versions? Can you try 0.7.7 or higher (but before 0.8.0)? That appears to be when the original issue was fixed. If you can narrow down the regression range, I can take a closer look.

If you can, it would also be helpful if you can try the same thing with a regular shell command. Does it match the ShellJS behavior or does the shell command behave like you expect?

@luiszun
Copy link
Author

luiszun commented May 3, 2022

Actually it still happens on 0.7.7 with exactly the same setup.
I guess its not a regression after all.

Regular shell command keeps data on file. Used the same /. at the end to overcome the "same file" exit on cp. Command finished with exit status 0 and contents were preserved.

luiszun@luiszun-box:~/tmp/test$ cp -r /home/luiszun/srcdir /home/luiszun/
cp: '/home/luiszun/srcdir' and '/home/luiszun/srcdir' are the same file
luiszun@luiszun-box:~/tmp/test$ cat /home/luiszun/srcdir/lol
deadbeef
luiszun@luiszun-box:~/tmp/test$ cp -r /home/luiszun/srcdir/. /home/luiszun/
luiszun@luiszun-box:~/tmp/test$ cat /home/luiszun/srcdir/lol
deadbeef
luiszun@luiszun-box:~/tmp/test$ cp -r /home/luiszun/srcdir/. /home/luiszun/
luiszun@luiszun-box:~/tmp/test$ echo $?
0
luiszun@luiszun-box:~/tmp/test$

@nfischer nfischer changed the title Data loss. Regression. shell.cp() Content of file is erased when trying to copy it to the folder it already belongs to Data loss. shell.cp() Content of file is erased when trying to copy it to the folder it already belongs to May 30, 2022
@nfischer nfischer added bash compat Compatibility issues with bash or POSIX behavior medium priority labels May 30, 2022
@nfischer
Copy link
Member

Thanks for confirming. I adjusted the title to remove the word "regression."

@nfischer
Copy link
Member

shelljs/shx#209 is very similar to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bash compat Compatibility issues with bash or POSIX behavior fix Bug/defect, or a fix for such a problem medium priority
Projects
None yet
Development

No branches or pull requests

2 participants