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


 544     char *name, int oflag, mode_t mode);
 545 static char *skipslashes(char *string, char *start);
 546 static void chop_endslashes(char *path);
 547 static pid_t compress_file(void);
 548 static void compress_back(void);
 549 static void decompress_file(void);
 550 static pid_t uncompress_file(void);
 551 static void *compress_malloc(size_t);
 552 static void check_compression(void);
 553 static char *bz_suffix(void);
 554 static char *gz_suffix(void);
 555 static char *xz_suffix(void);
 556 static char *add_suffix();
 557 static void wait_pid(pid_t);
 558 static void verify_compress_opt(const char *t);
 559 static void detect_compress(void);
 560 
 561 static  struct stat stbuf;
 562 
 563 static  char    *myname;

 564 static  int     checkflag = 0;
 565 static  int     Xflag, Fflag, iflag, hflag, Bflag, Iflag;
 566 static  int     rflag, xflag, vflag, tflag, mt, svmt, cflag, mflag, pflag;
 567 static  int     uflag;
 568 static  int     errflag;
 569 static  int     oflag;
 570 static  int     bflag, Aflag;
 571 static  int     Pflag;                  /* POSIX conformant archive */
 572 static  int     Eflag;                  /* Allow files greater than 8GB */
 573 static  int     atflag;                 /* traverse extended attributes */
 574 static  int     saflag;                 /* traverse extended sys attributes */
 575 static  int     Dflag;                  /* Data change flag */
 576 static  int     jflag;                  /* flag to use 'bzip2' */
 577 static  int     zflag;                  /* flag to use 'gzip' */
 578 static  int     Zflag;                  /* flag to use 'compress' */
 579 static  int     Jflag;                  /* flag to use 'xz' */
 580 static  int     aflag;                  /* flag to use autocompression */
 581 
 582 /* Trusted Extensions */
 583 static  int     Tflag;                  /* Trusted Extensions attr flags */


1121                         compress_back();
1122         } else if (xflag || tflag) {
1123                 /*
1124                  * for each argument, check to see if there is a "-I file" pair.
1125                  * if so, move the 3rd argument into "-I"'s place, build_table()
1126                  * using "file"'s name and increment argc one (the second
1127                  * increment appears in the for loop) which removes the two
1128                  * args "-I" and "file" from the argument vector.
1129                  */
1130                 for (argc = 0; argv[argc]; argc++) {
1131                         if (strcmp(argv[argc], "-I") == 0) {
1132                                 if (!argv[argc+1]) {
1133                                         (void) fprintf(stderr, gettext(
1134                                         "tar: missing argument for -I flag\n"));
1135                                         done(2);
1136                                 } else {
1137                                         Iflag = 1;
1138                                         argv[argc] = argv[argc+2];
1139                                         build_table(include_tbl, argv[++argc]);
1140                                 }













1141                         }
1142                 }

1143                 if (strcmp(usefile, "-") == 0) {
1144                         mt = dup(0);
1145                         ++bflag;
1146                         /* try to recover from short reads when reading stdin */
1147                         ++Bflag;
1148                 } else if ((mt = open(usefile, 0)) < 0)
1149                         vperror(1, "%s", usefile);
1150 
1151                 /* Decompress if the file is compressed */
1152 
1153                 if (strcmp(usefile, "-") != 0) {
1154                         check_compression();
1155                         if (compress_opt != NULL) {
1156                                 pid = uncompress_file();
1157                                 wait_pid(pid);
1158                         }
1159                 }
1160                 if (xflag) {






1161                         if (Aflag && vflag)
1162                                 (void) printf(gettext(
1163                                     "Suppressing absolute pathnames.\n"));
1164 
1165                         doxtract(argv);
1166                 } else if (tflag)
1167                         dotable(argv);
1168         }
1169         else
1170                 usage();
1171 
1172         done(Errflg);
1173 
1174         /* Not reached:  keep compiler quiet */
1175         return (1);
1176 }
1177 
1178 static void
1179 usage(void)
1180 {




 544     char *name, int oflag, mode_t mode);
 545 static char *skipslashes(char *string, char *start);
 546 static void chop_endslashes(char *path);
 547 static pid_t compress_file(void);
 548 static void compress_back(void);
 549 static void decompress_file(void);
 550 static pid_t uncompress_file(void);
 551 static void *compress_malloc(size_t);
 552 static void check_compression(void);
 553 static char *bz_suffix(void);
 554 static char *gz_suffix(void);
 555 static char *xz_suffix(void);
 556 static char *add_suffix();
 557 static void wait_pid(pid_t);
 558 static void verify_compress_opt(const char *t);
 559 static void detect_compress(void);
 560 
 561 static  struct stat stbuf;
 562 
 563 static  char    *myname;
 564 static  char    *xtract_chdir = NULL;
 565 static  int     checkflag = 0;
 566 static  int     Xflag, Fflag, iflag, hflag, Bflag, Iflag;
 567 static  int     rflag, xflag, vflag, tflag, mt, svmt, cflag, mflag, pflag;
 568 static  int     uflag;
 569 static  int     errflag;
 570 static  int     oflag;
 571 static  int     bflag, Aflag;
 572 static  int     Pflag;                  /* POSIX conformant archive */
 573 static  int     Eflag;                  /* Allow files greater than 8GB */
 574 static  int     atflag;                 /* traverse extended attributes */
 575 static  int     saflag;                 /* traverse extended sys attributes */
 576 static  int     Dflag;                  /* Data change flag */
 577 static  int     jflag;                  /* flag to use 'bzip2' */
 578 static  int     zflag;                  /* flag to use 'gzip' */
 579 static  int     Zflag;                  /* flag to use 'compress' */
 580 static  int     Jflag;                  /* flag to use 'xz' */
 581 static  int     aflag;                  /* flag to use autocompression */
 582 
 583 /* Trusted Extensions */
 584 static  int     Tflag;                  /* Trusted Extensions attr flags */


1122                         compress_back();
1123         } else if (xflag || tflag) {
1124                 /*
1125                  * for each argument, check to see if there is a "-I file" pair.
1126                  * if so, move the 3rd argument into "-I"'s place, build_table()
1127                  * using "file"'s name and increment argc one (the second
1128                  * increment appears in the for loop) which removes the two
1129                  * args "-I" and "file" from the argument vector.
1130                  */
1131                 for (argc = 0; argv[argc]; argc++) {
1132                         if (strcmp(argv[argc], "-I") == 0) {
1133                                 if (!argv[argc+1]) {
1134                                         (void) fprintf(stderr, gettext(
1135                                         "tar: missing argument for -I flag\n"));
1136                                         done(2);
1137                                 } else {
1138                                         Iflag = 1;
1139                                         argv[argc] = argv[argc+2];
1140                                         build_table(include_tbl, argv[++argc]);
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                                 }
1156                         }
1157                 }
1158                 if (strcmp(usefile, "-") == 0) {
1159                         mt = dup(0);
1160                         ++bflag;
1161                         /* try to recover from short reads when reading stdin */
1162                         ++Bflag;
1163                 } else if ((mt = open(usefile, 0)) < 0)
1164                         vperror(1, "%s", usefile);
1165 
1166                 /* Decompress if the file is compressed */
1167 
1168                 if (strcmp(usefile, "-") != 0) {
1169                         check_compression();
1170                         if (compress_opt != NULL) {
1171                                 pid = uncompress_file();
1172                                 wait_pid(pid);
1173                         }
1174                 }
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                         }
1182                         if (Aflag && vflag)
1183                                 (void) printf(gettext(
1184                                     "Suppressing absolute pathnames.\n"));
1185 
1186                         doxtract(argv);
1187                 } else if (tflag)
1188                         dotable(argv);
1189         }
1190         else
1191                 usage();
1192 
1193         done(Errflg);
1194 
1195         /* Not reached:  keep compiler quiet */
1196         return (1);
1197 }
1198 
1199 static void
1200 usage(void)
1201 {