bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] cp, mv: do preserve extended attributes even for read-only s


From: Pádraig Brady
Subject: Re: [PATCH] cp, mv: do preserve extended attributes even for read-only source files
Date: Sat, 5 Sep 2009 00:33:58 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071008)

Ondřej Vašík wrote:
> As reported in
> http://lists.gnu.org/archive/html/bug-coreutils/2009-08/msg00342.html by
> Ernest N. Mamikonyan, cp/mv fails to preserve extended attributes for
> read-only source files.
> Following patch fixes the issue for me, although maybe it's not perfect
> solution. But I don't know about better one at the moment.
> Test included...

Thanks for that, and especially the test.
It looks to me that the cause of this is actually a bug
in fsetxattr() (called by attr_copy_fd) as it's being
passed a writable fd, but still giving permission denied?

rsync does copy the xattrs as it uses a different approach,
which you can see comparing the strace output of cp and
rsync below:

strace -f rsync -X xattr xattr-copy
  open(".xattr-copy.w0p0Cr", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = 1
  fchmod(1, 0600)             = 0
  mmap2(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xb7dd5000
  write(1, "t\n"..., 2)       = 2
  close(1)                    = 0
  lstat64(".xattr-copy.w0p0Cr", {st_mode=S_IFREG|0600, st_size=2, ...}) = 0
  llistxattr(".xattr-copy.w0p0Cr", 0x9000038, 1024) = 0
  lsetxattr(".xattr-copy.w0p0Cr", "user.test", "test", 4, 0) = 0
  chmod(".xattr-copy.w0p0Cr", 0444) = 0
  rename(".xattr-copy.w0p0Cr", "xattr-copy1") = 0

strace cp --preserve=xattr xattr xattr-copy
  open("xattr-copy", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0444) = 4
  fstat64(4, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
  read(3, "t\n"..., 32768)                = 2
  write(4, "t\n"..., 2)                   = 2
  read(3, ""..., 32768)                   = 0
  flistxattr(3, (nil), 0)                 = 10
  flistxattr(3, 0xbff59780, 10)           = 10
  open("/etc/xattr.conf", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or 
directory)
  fgetxattr(3, "user.test", 0x0, 0)       = 4
  fgetxattr(3, "user.test", "test", 4)    = 4
  fsetxattr(4, "user.test", "test", 4, 0) = -1 EACCES (Permission denied

BTW, I think you forgot to restore the permissions in your patch.

cheers,
Pádraig.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]