From 279ec3aea031cf8865a409f754e8cac9f46bccd0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 22 Dec 2006 18:56:01 +0000 Subject: [PATCH] Preserve ACLs while copying. --- ChangeLog | 7 +++++++ lib/copy-file.c | 15 +++++++++++++++ modules/copy-file | 1 + 3 files changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index ed3978342..778f87ba0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 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. Use $SED instead of sed everywhere. diff --git a/lib/copy-file.c b/lib/copy-file.c index ca620dcb6..4314f4c6d 100644 --- 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 @@ copy_file_preserving (const char *src_filename, const char *dest_filename) 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 @@ copy_file_preserving (const char *src_filename, const char *dest_filename) #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 index 27eb0fee1..7e82ce81a 100644 --- a/modules/copy-file +++ b/modules/copy-file @@ -10,6 +10,7 @@ Depends-on: error safe-read full-write +acl binary-io exit gettext-h -- 2.11.0