# HG changeset patch # User Bruno Haible # Date 1166813761 0 # Node ID 4a26effdff28a70d300edde2bbdc4c2d6f81ee58 # Parent 049a8acd7495866f909f1263490d6dad88326271 Preserve ACLs while copying. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-12-22 Bruno Haible + + * lib/copy-file.c: Include acl.h. + (copy_file_preserving) [USE_ACL]: Use copy_acl instead of chmod. + Close the file descriptors only after being done with copy_acl. + * modules/copy-file (Depends-on): Add acl. + 2006-12-22 Bruno Haible * gnulib-tool (SED): New variable. diff --git a/lib/copy-file.c b/lib/copy-file.c --- a/lib/copy-file.c +++ b/lib/copy-file.c @@ -39,6 +39,7 @@ #include "error.h" #include "safe-read.h" #include "full-write.h" +#include "acl.h" #include "binary-io.h" #include "exit.h" #include "gettext.h" @@ -80,10 +81,12 @@ error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename); } +#if !USE_ACL if (close (dest_fd) < 0) error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename); if (close (src_fd) < 0) error (EXIT_FAILURE, errno, _("error after reading \"%s\""), src_filename); +#endif /* Preserve the access and modification times. */ #if HAVE_UTIME @@ -110,5 +113,17 @@ #endif /* Preserve the access permissions. */ +#if USE_ACL + if (copy_acl (src_filename, src_fd, dest_filename, dest_fd, mode)) + exit (EXIT_FAILURE); +#else chmod (dest_filename, mode); +#endif + +#if USE_ACL + if (close (dest_fd) < 0) + error (EXIT_FAILURE, errno, _("error writing \"%s\""), dest_filename); + if (close (src_fd) < 0) + error (EXIT_FAILURE, errno, _("error after reading \"%s\""), src_filename); +#endif } diff --git a/modules/copy-file b/modules/copy-file --- a/modules/copy-file +++ b/modules/copy-file @@ -10,6 +10,7 @@ error safe-read full-write +acl binary-io exit gettext-h