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

cp and rename directory with -r doesn't match unix behavior #256

Closed
jedwards1211 opened this issue Nov 30, 2015 · 6 comments
Closed

cp and rename directory with -r doesn't match unix behavior #256

jedwards1211 opened this issue Nov 30, 2015 · 6 comments
Assignees
Labels
fix Bug/defect, or a fix for such a problem

Comments

@jedwards1211
Copy link

As shown below, if I do cp -r a b with shelljs where a is a directory and b doesn't exist, shelljs creates b/a directories and the copies the contents of a into b/a. Instead, like in a unix shell, it should create b directory and copy the contents of a into b.

> mkdir a
> touch a/file.txt
> node
> require('shelljs/global')
{}
> cp('-r', 'a', 'b');
undefined
> 
(To exit, press ^C again or type .exit)
> 
> ls b/
a
> rm -rvf b
b/a/file.txt
b/a
b/
> cp -rvp a b
a -> b
a/file.txt -> b/file.txt
@aarjithn
Copy link

Possibly same as #101? Me too would like to get this fixed.

@nfischer
Copy link
Member

To get the behavior you want, you must specify a trailing '/'. Change your command to:

cp('-r', 'a/', 'b');

Please see #15.

I agree that this differs from the Linux behavior. How does this compare with the BSD behavior (such as on OS X)? I know that BSD utilities behave differently if a directory is has a trailing '/'. See this page for more details. This example is slightly different, but I believe the behavior differs in this case as well. If someone could confirm on OS X, that would be helpful.

I don't believe POSIX specifies which behavior is correct, but please correct me if I'm wrong.

@jedwards1211
Copy link
Author

@nfischer sorry, I shouldn't have said "in a unix shell", I actually ran my original example on OSX.

@nfischer
Copy link
Member

Oh, ok. I'm on Linux, so I can confirm that Linux behaves the way you describe. If OS X also behaves that way, then it sounds like this is not POSIX behavior, and should indeed be fixed.

For now though, does the trailing '/' workaround achieve what you need, @jedwards1211?

@jedwards1211
Copy link
Author

@nfischer it does, although of course I had just used a/* instead

@nfischer
Copy link
Member

nfischer commented Jan 8, 2016

Would any of you be able to test out #271 and make sure it works as expected? I've tested it, and it seems to resemble the Linux behavior fairly closely (will test again to be completely sure). It'd be great if you guys could confirm as well.

@ariporad ariporad added the fix Bug/defect, or a fix for such a problem label Jan 9, 2016
@ariporad ariporad assigned nfischer and unassigned nfischer Jan 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug/defect, or a fix for such a problem
Projects
None yet
Development

No branches or pull requests

4 participants