part 2

OK?

martijn@

diff --git cp.c cp.c
index 321e82f..fbf924c 100644
--- cp.c
+++ cp.c
@@ -395,9 +395,9 @@ copy(char *argv[], enum op type, int fts_options)
 
                switch (curr->fts_statp->st_mode & S_IFMT) {
                case S_IFLNK:
-                       if (copy_link(curr, !fts_dne(curr)))
+                       if ((cval = copy_link(curr, !fts_dne(curr))) == 1)
                                rval = 1;
-                       else if (vflag)
+                       if (!cval && vflag)
                                (void)fprintf(stdout, "%s -> %s\n",
                                    curr->fts_path, to.p_path);
                        break;
@@ -430,8 +430,8 @@ copy(char *argv[], enum op type, int fts_options)
                case S_IFBLK:
                case S_IFCHR:
                        if (Rflag) {
-                               if (copy_special(curr->fts_statp,
-                                   !fts_dne(curr)))
+                               if ((cval = copy_special(curr->fts_statp,
+                                   !fts_dne(curr))) == 1)
                                        rval = 1;
                        } else {
                                cval = copy_file(curr, fts_dne(curr));
@@ -445,7 +445,8 @@ copy(char *argv[], enum op type, int fts_options)
                        break;
                case S_IFIFO:
                        if (Rflag) {
-                               if (copy_fifo(curr->fts_statp, !fts_dne(curr)))
+                               if ((cval = copy_fifo(curr->fts_statp,
+                                   !fts_dne(curr))) == 1)
                                        rval = 1;
                        } else {
                                cval = copy_file(curr, fts_dne(curr));
diff --git utils.c utils.c
index 3a8d6b4..4a9219c 100644
--- utils.c
+++ utils.c
@@ -199,6 +199,8 @@ copy_link(FTSENT *p, int exists)
        int len;
        char name[PATH_MAX];
 
+       if (exists && !copy_overwrite())
+               return (2);
        if ((len = readlink(p->fts_path, name, sizeof(name)-1)) == -1) {
                warn("readlink: %s", p->fts_path);
                return (1);
@@ -218,6 +220,8 @@ copy_link(FTSENT *p, int exists)
 int
 copy_fifo(struct stat *from_stat, int exists)
 {
+       if (exists && !copy_overwrite())
+               return (2);
        if (exists && unlink(to.p_path)) {
                warn("unlink: %s", to.p_path);
                return (1);
@@ -232,6 +236,8 @@ copy_fifo(struct stat *from_stat, int exists)
 int
 copy_special(struct stat *from_stat, int exists)
 {
+       if (exists && !copy_overwrite())
+               return (2);
        if (exists && unlink(to.p_path)) {
                warn("unlink: %s", to.p_path);
                return (1);

Reply via email to