Hello,

For some code in Texinfo (not public yet), I needed to copy a file.  I
used the copy-file Gnulib module code, but I did not want to preserve
the owner and group as it is better in my case if the file owner is the
same as the generated output files owner.   So I modified the code not to
keep the owner.  The attached diff show the differences (I also comment
out copy_file_preserving and the associated gettext include as I do not
have a use for this variant, but it is not the important information).

I have no problem tracking the change in gnulib and updating the code.
However I thought that you may still be interested to know about my use
case in case it motivates you to add some flexibility on what is kept in
the copy_file function, or with a different function.

PS: this does not necessarily require a response, but in case, I am not
subscribed.

-- 
Pat
--- ./gnulib/lib/copy-file.c	2024-08-23 14:44:26.617375278 +0200
+++ copy-file_but_owner.c	2024-08-23 14:44:56.321376126 +0200
@@ -19,7 +19,7 @@
 #include <config.h>
 
 /* Specification.  */
-#include "copy-file.h"
+#include "copy-file_but_owner.h"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -37,14 +37,19 @@
 #include "acl.h"
 #include "binary-io.h"
 #include "quote.h"
+/*
 #include "gettext.h"
 
 #define _(str) gettext (str)
+ */
 
 enum { IO_SIZE = 32 * 1024 };
 
+/* based on gnulib qcopy_file_preserving modified to remove owner
+   preservation */
+
 int
-qcopy_file_preserving (const char *src_filename, const char *dest_filename)
+qcopy_file_preserving_but_owner (const char *src_filename, const char *dest_filename)
 {
   int err = 0;
   int src_fd;
@@ -141,10 +146,14 @@
     utimens (dest_filename, ts);
   }
 
+/*
 #if HAVE_CHOWN
+ */
   /* Preserve the owner and group.  */
+ /*
   ignore_value (chown (dest_filename, statbuf.st_uid, statbuf.st_gid));
 #endif
+ */
 
   /* Preserve the access permissions.  */
 #if USE_ACL
@@ -180,6 +189,7 @@
   return err;
 }
 
+/*
 void
 copy_file_preserving (const char *src_filename, const char *dest_filename)
 {
@@ -219,3 +229,4 @@
       abort ();
     }
 }
+*/
--- ./gnulib/lib/copy-file.h	2024-08-23 14:44:26.617375278 +0200
+++ copy-file_but_owner.h	2024-08-23 14:44:56.321376126 +0200
@@ -33,21 +33,23 @@
   GL_COPY_ERR_SET_ACL = -7
 };
 
+/* gnulib qcopy_file_preserving modified to remove owner preservation */
 /* Copy a regular file: from src_filename to dest_filename.
    The destination file is assumed to be a backup file.
-   Modification times, owner, group and access permissions are preserved as
+   Modification times and access permissions are preserved as
    far as possible.
    Return 0 if successful, otherwise set errno and return one of the error
    codes above.  */
-extern int qcopy_file_preserving (const char *src_filename, const char *dest_filename);
+extern int qcopy_file_preserving_but_owner (const char *src_filename, const char *dest_filename);
 
 /* Copy a regular file: from src_filename to dest_filename.
    The destination file is assumed to be a backup file.
    Modification times, owner, group and access permissions are preserved as
    far as possible.
    Exit upon failure.  */
+/*
 extern void copy_file_preserving (const char *src_filename, const char *dest_filename);
-
+*/
 
 #ifdef __cplusplus
 }

Reply via email to