How to use cp.exe from Cygwin and preserve permissions [closed]
Asked Answered
B

2

7

I'm using cp.exe from Cygwin to copy files in Windows 7. Unfortunately, when I do the permissions of the file change.

I've tried using:

cp --preserve=all

But that doesn't work either, and when I check the security of the original file vs the copy, the copy has different permissions.

Clearly there must be a way to preserve permissions when copying using Cygwin, but I can't find it.

Battology answered 7/12, 2011 at 19:11 Comment(3)
cp --preserver=all is probably the best you're going to be able to do with the cp command. Exactly what permissions are different? Are you copying to a FAT32 file system? If so, it may not support the permissions you want.Garcia
It seems like the original permissions are pretty much ignored. It's NTFS - Win7.Battology
@KeithThompson cp --preserve=all doesn't work on win7 atleast. cygwin cp permissions are still out of whack!Bobbitt
B
8

I did some more investigation about this after asking the question above.

Per this discussion with one of Cygwin's developers, it appears that Cygwin doesn't care about Windows permissions, and just sticks with the POSIX ones.

From what I can tell, POSIX permissions are a whole separate thing from the Windows ones, so yes, it's great that they're supported, but ultimately, Cygwin can't copy files and maintain normal Windows permissions. Making it useless to me. Much better to use Python or Ruby.

I would love to be proven wrong though.

Battology answered 8/12, 2011 at 0:53 Comment(2)
This burned me today, very disappointing. Fixed with: getfacl src-file.txt | setfacl -f - dest-file.txt Why can't Cygwin's cp do that for me?! Another option might be aliasing cp to an equivalent rsync command, similar to this answer.Postwar
I was able to copy the files with cp after setting the Total Control Permissions on the destination file.Hammad
B
11

I believe adding option noacl to the /cygdrive mount point in /etc/fstab will do what you want.

$ cat fstab
# For a description of the file format, see the Users Guide   
# http://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0
none /cygdrive cygdrive binary,posix=0,user,noacl 0 0

See http://cygwin.com/cygwin-ug-net/using.html#mount-table and discussion from the cygwin mailing list.

Bookbinder answered 14/3, 2013 at 21:9 Comment(3)
Doesn't work, a simple mkdir breaks the NTFS ACL inheritance and creates a bunch of new permissions, which sometimes are also making directories unbrowsable for the user that originally created them (often happens during rsync operation). So mounting with noacl is only a partial solution, still this does not make cygwin behave the way I expect. There are many discussions on this topic, for me it's a clear flaw of cygwin.Convertible
@Convertible I checked with latest Cygwin and CMD.exe mkdir set same permission as Cygwin with path under noacl effect. Check you /etc/fstab.Fresnel
@Convertible you have to add this too F:\cygwin / ntfs override,binary,auto,noacl 0 0Flytrap
B
8

I did some more investigation about this after asking the question above.

Per this discussion with one of Cygwin's developers, it appears that Cygwin doesn't care about Windows permissions, and just sticks with the POSIX ones.

From what I can tell, POSIX permissions are a whole separate thing from the Windows ones, so yes, it's great that they're supported, but ultimately, Cygwin can't copy files and maintain normal Windows permissions. Making it useless to me. Much better to use Python or Ruby.

I would love to be proven wrong though.

Battology answered 8/12, 2011 at 0:53 Comment(2)
This burned me today, very disappointing. Fixed with: getfacl src-file.txt | setfacl -f - dest-file.txt Why can't Cygwin's cp do that for me?! Another option might be aliasing cp to an equivalent rsync command, similar to this answer.Postwar
I was able to copy the files with cp after setting the Total Control Permissions on the destination file.Hammad

© 2022 - 2024 — McMap. All rights reserved.