Print this page
OS-1626 tar -C support on extract would be nice

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/tar/tar.c
          +++ new/usr/src/cmd/tar/tar.c
↓ open down ↓ 553 lines elided ↑ open up ↑
 554  554  static char *gz_suffix(void);
 555  555  static char *xz_suffix(void);
 556  556  static char *add_suffix();
 557  557  static void wait_pid(pid_t);
 558  558  static void verify_compress_opt(const char *t);
 559  559  static void detect_compress(void);
 560  560  
 561  561  static  struct stat stbuf;
 562  562  
 563  563  static  char    *myname;
      564 +static  char    *xtract_chdir = NULL;
 564  565  static  int     checkflag = 0;
 565  566  static  int     Xflag, Fflag, iflag, hflag, Bflag, Iflag;
 566  567  static  int     rflag, xflag, vflag, tflag, mt, svmt, cflag, mflag, pflag;
 567  568  static  int     uflag;
 568  569  static  int     errflag;
 569  570  static  int     oflag;
 570  571  static  int     bflag, Aflag;
 571  572  static  int     Pflag;                  /* POSIX conformant archive */
 572  573  static  int     Eflag;                  /* Allow files greater than 8GB */
 573  574  static  int     atflag;                 /* traverse extended attributes */
↓ open down ↓ 557 lines elided ↑ open up ↑
1131 1132                          if (strcmp(argv[argc], "-I") == 0) {
1132 1133                                  if (!argv[argc+1]) {
1133 1134                                          (void) fprintf(stderr, gettext(
1134 1135                                          "tar: missing argument for -I flag\n"));
1135 1136                                          done(2);
1136 1137                                  } else {
1137 1138                                          Iflag = 1;
1138 1139                                          argv[argc] = argv[argc+2];
1139 1140                                          build_table(include_tbl, argv[++argc]);
1140 1141                                  }
     1142 +                        } else if (strcmp(argv[argc], "-C") == 0) {
     1143 +                                if (!argv[argc+1]) {
     1144 +                                        (void) fprintf(stderr, gettext("tar: "
     1145 +                                            "missing argument for -C flag\n"));
     1146 +                                        done(2);
     1147 +                                } else if (xtract_chdir != NULL) {
     1148 +                                        (void) fprintf(stderr, gettext("tar: "
     1149 +                                            "extract should have only one -C "
     1150 +                                            "flag\n"));
     1151 +                                        done(2);
     1152 +                                } else {
     1153 +                                        argv[argc] = argv[argc+2];
     1154 +                                        xtract_chdir = argv[++argc];
     1155 +                                }
1141 1156                          }
1142 1157                  }
1143 1158                  if (strcmp(usefile, "-") == 0) {
1144 1159                          mt = dup(0);
1145 1160                          ++bflag;
1146 1161                          /* try to recover from short reads when reading stdin */
1147 1162                          ++Bflag;
1148 1163                  } else if ((mt = open(usefile, 0)) < 0)
1149 1164                          vperror(1, "%s", usefile);
1150 1165  
1151 1166                  /* Decompress if the file is compressed */
1152 1167  
1153 1168                  if (strcmp(usefile, "-") != 0) {
1154 1169                          check_compression();
1155 1170                          if (compress_opt != NULL) {
1156 1171                                  pid = uncompress_file();
1157 1172                                  wait_pid(pid);
1158 1173                          }
1159 1174                  }
1160 1175                  if (xflag) {
     1176 +                        if (xtract_chdir != NULL) {
     1177 +                                if (tar_chdir(xtract_chdir) < 0) {
     1178 +                                        vperror(1, gettext("can't change "
     1179 +                                            "directories to %s"), xtract_chdir);
     1180 +                                }
     1181 +                        }
1161 1182                          if (Aflag && vflag)
1162 1183                                  (void) printf(gettext(
1163 1184                                      "Suppressing absolute pathnames.\n"));
1164 1185  
1165 1186                          doxtract(argv);
1166 1187                  } else if (tflag)
1167 1188                          dotable(argv);
1168 1189          }
1169 1190          else
1170 1191                  usage();
↓ open down ↓ 8284 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX