On Thu, 17 Dec 2015, Ted Unangst wrote:
> Carsten Kunze wrote:
> > Ted Unangst <t...@tedunangst.com> wrote:
> > 
> > > Probably not intended. Just an artifact left over from the era before you
> > > could set times on symlinks. (not likely that many people care, either.)
> > 
> > I do care--I have a sync software (similar to rsync) which compares mtime 
> > and length.  lstat needs do be done anyway so there are just two integer 
> > compares instead of two readlink and strcmp.  This software "failes" after 
> > a "cp -RpP".  If a patch is accepted I'd like to file a bug report with a 
> > patch.
> 
> Sure. I just meant it's gone unnoticed for a long time, but we can still fix
> it. patches welcome.

I think simply replacing setlink(path) with setfile(path,-1) is the Right 
Thing.  That'll preserve the flags and the (ignored) mode as well.


Philip Guenther


Index: extern.h
===================================================================
RCS file: /data/src/openbsd/src/bin/cp/extern.h,v
retrieving revision 1.14
diff -u -p -r1.14 extern.h
--- extern.h    16 Jan 2015 06:39:31 -0000      1.14
+++ extern.h    17 Dec 2015 17:12:33 -0000
@@ -50,6 +50,5 @@ int   copy_file(FTSENT *, int);
 int    copy_link(FTSENT *, int);
 int    copy_special(struct stat *, int);
 int    setfile(struct stat *, int);
-int    setlink(struct stat *);
 void   usage(void);
 __END_DECLS
Index: utils.c
===================================================================
RCS file: /data/src/openbsd/src/bin/cp/utils.c,v
retrieving revision 1.38
diff -u -p -r1.38 utils.c
--- utils.c     16 Nov 2015 21:35:58 -0000      1.38
+++ utils.c     17 Dec 2015 17:12:25 -0000
@@ -217,7 +217,7 @@ copy_link(FTSENT *p, int exists)
                warn("symlink: %s", name);
                return (1);
        }
-       return (pflag ? setlink(p->fts_statp) : 0);
+       return (pflag ? setfile(p->fts_statp, -1) : 0);
 }
 
 int
@@ -300,20 +300,6 @@ setfile(struct stat *fs, int fd)
                        rval = 1;
                }
        return (rval);
-}
-
-
-int
-setlink(struct stat *fs)
-{
-
-       if (lchown(to.p_path, fs->st_uid, fs->st_gid)) {
-               if (errno != EPERM) {
-                       warn("lchown: %s", to.p_path);
-                       return (1);
-               }
-       }
-       return (0);
 }

Reply via email to