This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: cp.ese bug report -- possible fix?


Well, I've attached a patch for this bug.  However, it uncovered another 
problem with 'cp -p src dest', when src is not owned by the current user.

(AROUND LINE 1170 in fileutils/src/copy.c):

   /* Permissions of newly-created regular files were set upon `open' in
      copy_reg.  But don't return early if there were any special bits and
      we had to run chown, because the chown must have reset those bits.  */
   if ((new_dst && copied_as_regular)
       && !(ran_chown && (src_mode & ~S_IRWXUGO)))
     return delayed_fail;

   if ((x->preserve_chmod_bits || new_dst)
       && (x->copy_as_regular || S_ISREG (src_type) || S_ISDIR (src_type)))
     {
       if (chmod (dst_path, get_dest_mode (x, src_mode)))    <<<<< HERE
    {
#ifdef __CYGWIN__
    char *p;

The chmod command returns with ENOENT.  I have no idea why; the file has 
already been created at this point...

--Chuck
diff -ur fileutils-4.1-1/src/copy.c fileutils-4.1-1a/src/copy.c
--- fileutils-4.1-1/src/copy.c	Fri Jun 15 15:20:08 2001
+++ fileutils-4.1-1a/src/copy.c	Sat May 11 17:50:11 2002
@@ -37,12 +37,22 @@
 #include "quote.h"
 #include "same.h"
 
+#if defined(__CYGWIN__)
+#define DO_CHOWN(Chown, File, New_uid, New_gid)				\
+  (Chown (File, New_uid, New_gid)					\
+   /* On cygwin, SYSTEM has uid = 18 and we treat that as \
+      root.  Also, cygwin returns EACCES when non-"root" \
+      attempts to chown ... */ \
+   && ((errno != EPERM && errno != EINVAL && errno != EACCES) || \
+   x->myeuid == 18))
+#else
 #define DO_CHOWN(Chown, File, New_uid, New_gid)				\
   (Chown (File, New_uid, New_gid)					\
    /* If non-root uses -p, it's ok if we can't preserve ownership.	\
       But root probably wants to know, e.g. if NFS disallows it,	\
       or if the target system doesn't support file ownership.  */	\
    && ((errno != EPERM && errno != EINVAL) || x->myeuid == 0))
+#endif
 
 #define SAME_OWNER(A, B) ((A).st_uid == (B).st_uid)
 #define SAME_GROUP(A, B) ((A).st_gid == (B).st_gid)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]