Fix for copy.c preserving st_author

Marcus Brinkmann <[email protected]>
Newsgroups gmane.comp.gnu.fileutils.bugs
Message-ID <[email protected]>
Hi,

the copy.c change to preserve the author field that was submitted by Alfred
was broken.  It has a gross type error (getdport takes an fd and not a
string), so it was obviously never compiled with warnings enabled or tested.

Here is the correct one.  BTW, wouldn't it make more sense to open the file
once and then use fchmod etc?  Then Alfred's approach would be better, with
dst_path replaced by the appropriate file descriptor.

Thanks,
Marcus

2002-08-17  Marcus Brinkmann  <[email protected]>

	* src/copy.c (copy_internal): Fix athor preservation code.

--- fileutils-4.1.10.old/src/copy.c	Fri Jun 21 14:07:40 2002
+++ fileutils-4.1.10/src/copy.c	Sat Aug 17 20:42:40 2002
@@ -1517,11 +1517,17 @@ copy_internal (const char *src_path, con
 #if HAVE_STRUCT_STAT_ST_AUTHOR
   /* Preserve the st_author field.  */
   {
-    file_t file = getdport (dst_path);
-    if (file_chauthor (file, src_sb.st_author))
-      error (0, errno, _("failed to preserve authorship for %s"),
-	     quote (dst_path));
-    mach_port_deallocate (mach_task_self (), file);
+    file_t file = file_name_lookup (dst_path, O_NORW, 0);
+    if (file == MACH_PORT_NULL)
+      error (0, errno, _("failed to lookup file %s"), quote (dst_path));
+    else
+      {
+	int err = file_chauthor (file, src_sb.st_author);
+	if (err)
+	  error (0, err, _("failed to preserve authorship for %s"),
+		 quote (dst_path));
+	mach_port_deallocate (mach_task_self (), file);
+      }
   }
 #endif
 


-- 
`Rhubarb is no Egyptian god.' GNU      http://www.gnu.org    [email protected]
Marcus Brinkmann              The Hurd http://www.gnu.org/software/hurd/
[email protected]
http://www.marcus-brinkmann.de/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.