Source-Changes-HG archive

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

[src/netbsd-2-0]: src/bin/pax Pull up revision 1.54-1.56 via patch (requested...



details:   https://anonhg.NetBSD.org/src/rev/6b02673d47c2
branches:  netbsd-2-0
changeset: 561458:6b02673d47c2
user:      tron <tron%NetBSD.org@localhost>
date:      Fri Jun 18 09:14:00 2004 +0000

description:
Pull up revision 1.54-1.56 via patch (requested by dillo in ticket #507):
Restructure the code to make it more readable. No functional changes.
PR/25934: Dieter Baron: tar and hardlinks with long filenames don't work.
- always put the @LongLink tag on the name, not the long-link name.
- pass in what type of long name record we want to create; one for long-name
  or long-link name.
XXX: We should get rid of the switch too.
PR/25934: Dieter Baron: hard links with long names still fail.
As mentioned in the previous commit, the switch statement in the longlink()
needed simplification and it was a bit incorrect. Only depend on the passed
type to determine what kind of gnu longlink to produce. Don't try to deduce
it from the archive file type.

diffstat:

 bin/pax/tar.c |  83 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 44 insertions(+), 39 deletions(-)

diffs (176 lines):

diff -r 9f067447fe09 -r 6b02673d47c2 bin/pax/tar.c
--- a/bin/pax/tar.c     Fri Jun 18 09:07:20 2004 +0000
+++ b/bin/pax/tar.c     Fri Jun 18 09:14:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tar.c,v 1.47.2.4 2004/04/28 03:28:54 grant Exp $       */
+/*     $NetBSD: tar.c,v 1.47.2.5 2004/06/18 09:14:00 tron Exp $        */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)tar.c      8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: tar.c,v 1.47.2.4 2004/04/28 03:28:54 grant Exp $");
+__RCSID("$NetBSD: tar.c,v 1.47.2.5 2004/06/18 09:14:00 tron Exp $");
 #endif
 #endif /* not lint */
 
@@ -69,7 +69,7 @@
  */
 
 static int expandname(char *, size_t,  char **, const char *, size_t);
-static void longlink(ARCHD *);
+static void longlink(ARCHD *, int);
 static u_long tar_chksm(char *, int);
 static char *name_split(char *, int);
 static int ul_oct(u_long, char *, int, int);
@@ -95,6 +95,8 @@
 char *gnu_link_string;                 /* ././@LongLink hackery link */
 static int gnu_short_trailer;          /* gnu short trailer */
 
+static const char LONG_LINK[] = "././@LongLink";
+
 static int
 check_sum(char *hd, size_t hdlen, char *bl, size_t bllen, int quiet)
 {
@@ -491,8 +493,6 @@
                arcn->sb.st_mode |= S_IFREG;
                break;
        case LONGLINKTYPE:
-               arcn->type = PAX_GLL;
-               /* FALLTHROUGH */
        case LONGNAMETYPE:
                /*
                 * GNU long link/file; we tag these here and let the
@@ -500,6 +500,8 @@
                 */
                if (hd->linkflag != LONGLINKTYPE)
                        arcn->type = PAX_GLF;
+               else
+                       arcn->type = PAX_GLL;
                arcn->pad = TAR_PAD(arcn->sb.st_size);
                arcn->skip = arcn->sb.st_size;
                break;
@@ -903,9 +905,6 @@
                }
                break;
        case LONGLINKTYPE:
-               if (is_gnutar)
-                       arcn->type = PAX_GLL;
-               /* FALLTHROUGH */
        case LONGNAMETYPE:
                if (is_gnutar) {
                        /*
@@ -914,6 +913,8 @@
                         */
                        if (hd->typeflag != LONGLINKTYPE)
                                arcn->type = PAX_GLF;
+                       else
+                               arcn->type = PAX_GLL;
                        arcn->pad = TAR_PAD(arcn->sb.st_size);
                        arcn->skip = arcn->sb.st_size;
                } else {
@@ -955,29 +956,28 @@
 }
 
 static void
-longlink(ARCHD *arcn)
+longlink(ARCHD *arcn, int type)
 {
        ARCHD larc;
 
-       memset(&larc, 0, sizeof(larc));
+       (void)memset(&larc, 0, sizeof(larc));
 
-       switch (arcn->type) {
-       case PAX_SLK:
-       case PAX_HRG:
-       case PAX_HLK:
-               larc.type = PAX_GLL;
-               larc.ln_nlen = strlcpy(larc.ln_name, "././@LongLink",
-                   sizeof(larc.ln_name));
+       larc.type = type;
+       larc.nlen = strlcpy(larc.name, LONG_LINK, sizeof(larc.name));
+
+       switch (type) {
+       case PAX_GLL:
                gnu_hack_string = arcn->ln_name;
                gnu_hack_len = arcn->ln_nlen + 1;
                break;
-       default:
-               larc.nlen = strlcpy(larc.name, "././@LongLink",
-                   sizeof(larc.name));
+       case PAX_GLF:
                gnu_hack_string = arcn->name;
                gnu_hack_len = arcn->nlen + 1;
-               larc.type = PAX_GLF;
+               break;
+       default:
+               errx(1, "Invalid type in GNU longlink %d\n", type);
        }
+
        /*
         * We need a longlink now.
         */
@@ -1004,29 +1004,34 @@
        char hdblk[sizeof(HD_USTAR)];
        const char *user, *group;
 
-       /*
-        * check for those file system types ustar cannot store
-        */
-       if (arcn->type == PAX_SCK) {
+       switch (arcn->type) {
+       case PAX_SCK:
+               /*
+                * check for those file system types ustar cannot store
+                */
                if (!is_gnutar)
                        tty_warn(1, "Ustar cannot archive a socket %s",
                            arcn->org_name);
                return(1);
-       }
 
-       /*
-        * check the length of the linkname
-        */
-       if (((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) ||
-           (arcn->type == PAX_HRG)) &&
-           (arcn->ln_nlen >= sizeof(hd->linkname))){
-               if (is_gnutar) {
-                       longlink(arcn);
-               } else {
-                       tty_warn(1, "Link name too long for ustar %s",
-                           arcn->ln_name);
-                       return(1);
+       case PAX_SLK:
+       case PAX_HLK:
+       case PAX_HRG:
+               /*
+                * check the length of the linkname
+                */
+               if (arcn->ln_nlen >= sizeof(hd->linkname)) {
+                       if (is_gnutar) {
+                               longlink(arcn, PAX_GLL);
+                       } else {
+                               tty_warn(1, "Link name too long for ustar %s",
+                                   arcn->ln_name);
+                               return(1);
+                       }
                }
+               break;
+       default:
+               break;
        }
 
        /*
@@ -1035,7 +1040,7 @@
         */
        if ((pt = name_split(arcn->name, arcn->nlen)) == NULL) {
                if (is_gnutar) {
-                       longlink(arcn);
+                       longlink(arcn, PAX_GLF);
                        pt = arcn->name;
                } else {
                        tty_warn(1, "File name too long for ustar %s",



Home | Main Index | Thread Index | Old Index