Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/pax Apply user supplied patterns first before applying a...



details:   https://anonhg.NetBSD.org/src/rev/baf4e1c87404
branches:  trunk
changeset: 573228:baf4e1c87404
user:      jmc <jmc%NetBSD.org@localhost>
date:      Sun Jan 23 06:19:03 2005 +0000

description:
Apply user supplied patterns first before applying actions for -A. This way pax
behavior WRT to patterns lines up with the example in the documentation
and how other implementations do it as well since -A is a non-standard
option/behavior. Fixes items noted in PR#23776

diffstat:

 bin/pax/ar_subs.c |  27 +++++++++++---------
 bin/pax/pat_rep.c |  69 +++++++++++++++++++++++++++---------------------------
 2 files changed, 50 insertions(+), 46 deletions(-)

diffs (181 lines):

diff -r fc317c08a72a -r baf4e1c87404 bin/pax/ar_subs.c
--- a/bin/pax/ar_subs.c Sun Jan 23 03:14:31 2005 +0000
+++ b/bin/pax/ar_subs.c Sun Jan 23 06:19:03 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ar_subs.c,v 1.34 2004/10/22 21:00:18 jmc Exp $ */
+/*     $NetBSD: ar_subs.c,v 1.35 2005/01/23 06:19:03 jmc Exp $ */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)ar_subs.c  8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: ar_subs.c,v 1.34 2004/10/22 21:00:18 jmc Exp $");
+__RCSID("$NetBSD: ar_subs.c,v 1.35 2005/01/23 06:19:03 jmc Exp $");
 #endif
 #endif /* not lint */
 
@@ -118,9 +118,6 @@
                        continue;
                }
 
-               if (arcn->name[0] == '/' && !check_Aflag()) {
-                       memmove(arcn->name, arcn->name + 1, strlen(arcn->name));
-               }
                /*
                 * check for pattern, and user specified options match.
                 * When all patterns are matched we are done.
@@ -141,8 +138,13 @@
                         */
                        if ((res = mod_name(arcn)) < 0)
                                break;
-                       if (res == 0)
+                       if (res == 0) {
+                               if (arcn->name[0] == '/' && !check_Aflag()) {
+                                       memmove(arcn->name, arcn->name + 1, 
+                                           strlen(arcn->name));
+                               }
                                ls_list(arcn, now, stdout);
+                       }
                        /*
                         * if there's an error writing to stdout then we must
                         * stop now -- we're probably writing to a pipe that
@@ -229,9 +231,6 @@
                        continue;
                }
 
-               if (arcn->name[0] == '/' && !check_Aflag()) {
-                       memmove(arcn->name, arcn->name + 1, strlen(arcn->name));
-               }
                /*
                 * check for pattern, and user specified options match. When
                 * all the patterns are matched we are done
@@ -291,6 +290,9 @@
                        continue;
                }
 
+               if (arcn->name[0] == '/' && !check_Aflag()) {
+                       memmove(arcn->name, arcn->name + 1, strlen(arcn->name));
+               }
                /*
                 * Non standard -Y and -Z flag. When the existing file is
                 * same age or newer skip; ignore this for GNU long links.
@@ -497,9 +499,6 @@
                        }
                }
 
-               if (arcn->name[0] == '/' && !check_Aflag()) {
-                       memmove(arcn->name, arcn->name + 1, strlen(arcn->name));
-               }
                /*
                 * Now modify the name as requested by the user
                 */
@@ -513,6 +512,10 @@
                        break;
                }
 
+               if (arcn->name[0] == '/' && !check_Aflag()) {
+                       memmove(arcn->name, arcn->name + 1, strlen(arcn->name));
+               }
+
                if ((res > 0) || (docrc && (set_crc(arcn, fd) < 0))) {
                        /*
                         * unable to obtain the crc we need, close the file,
diff -r fc317c08a72a -r baf4e1c87404 bin/pax/pat_rep.c
--- a/bin/pax/pat_rep.c Sun Jan 23 03:14:31 2005 +0000
+++ b/bin/pax/pat_rep.c Sun Jan 23 06:19:03 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pat_rep.c,v 1.22 2005/01/21 20:23:44 dsl Exp $ */
+/*     $NetBSD: pat_rep.c,v 1.23 2005/01/23 06:19:03 jmc Exp $ */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)pat_rep.c  8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: pat_rep.c,v 1.22 2005/01/21 20:23:44 dsl Exp $");
+__RCSID("$NetBSD: pat_rep.c,v 1.23 2005/01/23 06:19:03 jmc Exp $");
 #endif
 #endif /* not lint */
 
@@ -653,38 +653,6 @@
 {
        int res = 0;
 
-       /*
-        * Strip off leading '/' if appropriate.
-        * Currently, this option is only set for the tar format.
-        */
-       if (rmleadslash && arcn->name[0] == '/') {
-               if (arcn->name[1] == '\0') {
-                       arcn->name[0] = '.';
-               } else {
-                       (void)memmove(arcn->name, &arcn->name[1],
-                           strlen(arcn->name));
-                       arcn->nlen--;
-               }
-               if (rmleadslash < 2) {
-                       rmleadslash = 2;
-                       tty_warn(0, "Removing leading / from absolute path names in the archive");
-               }
-       }
-       if (rmleadslash && arcn->ln_name[0] == '/' &&
-           (arcn->type == PAX_HLK || arcn->type == PAX_HRG)) {
-               if (arcn->ln_name[1] == '\0') {
-                       arcn->ln_name[0] = '.';
-               } else {
-                       (void)memmove(arcn->ln_name, &arcn->ln_name[1],
-                           strlen(arcn->ln_name));
-                       arcn->ln_nlen--;
-               }
-               if (rmleadslash < 2) {
-                       rmleadslash = 2;
-                       tty_warn(0, "Removing leading / from absolute path names in the archive");
-               }
-       }
-
        if (secure) {
                if (checkdotdot(arcn->name)) {
                        tty_warn(0, "Ignoring file containing `..' (%s)",
@@ -745,6 +713,39 @@
                    (arcn->type == PAX_HRG))
                        sub_name(arcn->ln_name, &(arcn->ln_nlen), sizeof(arcn->ln_name));
        }
+
+       /*
+        * Strip off leading '/' if appropriate.
+        * Currently, this option is only set for the tar format.
+        */
+       if (rmleadslash && arcn->name[0] == '/') {
+               if (arcn->name[1] == '\0') {
+                       arcn->name[0] = '.';
+               } else {
+                       (void)memmove(arcn->name, &arcn->name[1],
+                           strlen(arcn->name));
+                       arcn->nlen--;
+               }
+               if (rmleadslash < 2) {
+                       rmleadslash = 2;
+                       tty_warn(0, "Removing leading / from absolute path names in the archive");
+               }
+       }
+       if (rmleadslash && arcn->ln_name[0] == '/' &&
+           (arcn->type == PAX_HLK || arcn->type == PAX_HRG)) {
+               if (arcn->ln_name[1] == '\0') {
+                       arcn->ln_name[0] = '.';
+               } else {
+                       (void)memmove(arcn->ln_name, &arcn->ln_name[1],
+                           strlen(arcn->ln_name));
+                       arcn->ln_nlen--;
+               }
+               if (rmleadslash < 2) {
+                       rmleadslash = 2;
+                       tty_warn(0, "Removing leading / from absolute path names in the archive");
+               }
+       }
+
        return(res);
 }
 



Home | Main Index | Thread Index | Old Index