diff lib/copy-file.c @ 7742:4a26effdff28

Preserve ACLs while copying.
author Bruno Haible <bruno@clisp.org>
date Fri, 22 Dec 2006 18:56:01 +0000
parents 1c4ed7637c24
children cb2590895141
line wrap: on
line diff
--- 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
 }