X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Ftar.c;h=7f27988481f79039bc0e1a8a47e2420dd3e6ea11;hb=c72ef8c1738769feb53b0ebaaf4fccfe755c2610;hp=24d26d221696b8a8651beb15dcb82635f20eff90;hpb=2ea583242fb762ca1803f3cef62c155d792e2a32;p=chaz%2Ftar diff --git a/src/tar.c b/src/tar.c index 24d26d2..7f27988 100644 --- a/src/tar.c +++ b/src/tar.c @@ -1,5 +1,5 @@ /* Tar -- a tape archiver. - Copyright (C) 1988 Free Software Foundation + Copyright (C) 1988, 1992 Free Software Foundation This file is part of GNU Tar. @@ -27,6 +27,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include /* Needed for typedefs in tar.h */ #include "getopt.h" #include "regex.h" +#include "fnmatch.h" /* * The following causes "tar.h" to produce definitions of all the @@ -103,7 +104,6 @@ void name_add(); void name_init(); void options(); char *un_quote_string(); -int wildmat(); #ifndef S_ISLNK #define lstat stat @@ -186,6 +186,13 @@ struct option long_options[] = {"compress-block", 0, &f_compress, 2}, {"sparse", 0, &f_sparse_files, 1}, {"tape-length", 1, 0, 'L'}, + {"remove-files", 0, &f_remove_files, 1}, + {"ignore-failed-read", 0, &f_ignore_failed_read, 1}, + {"checkpoint", 0, &f_checkpoint, 1}, + {"show-omitted-dirs", 0, &f_show_omitted_dirs, 1}, + {"volno-file", 1, 0, 17}, + {"force-local", 0, &f_force_local, 1}, + {"atime-preserve", 0, &f_atime_preserve, 1}, {0, 0, 0, 0} }; @@ -209,6 +216,9 @@ main(argc, argv) if(!n_argv) name_init(argc, argv); + if (f_volno_file) + init_volume_number (); + switch(cmd_mode) { case CMD_CAT: case CMD_UPDATE: @@ -225,7 +235,7 @@ main(argc, argv) break; case CMD_EXTRACT: if (f_volhdr) { - char *err; + const char *err; label_pattern = (struct re_pattern_buffer *) ck_malloc (sizeof *label_pattern); err = re_compile_pattern (f_volhdr, strlen (f_volhdr), @@ -243,7 +253,7 @@ main(argc, argv) break; case CMD_LIST: if (f_volhdr) { - char *err; + const char *err; label_pattern = (struct re_pattern_buffer *) ck_malloc (sizeof *label_pattern); err = re_compile_pattern (f_volhdr, strlen (f_volhdr), @@ -270,9 +280,11 @@ main(argc, argv) break; case CMD_NONE: msg("you must specify exactly one of the r, c, t, x, or d options\n"); - fprintf(stderr,"For more information, type ``%s +help''.\n",tar); + fprintf(stderr,"For more information, type ``%s --help''.\n",tar); exit(EX_ARGSBAD); } + if (f_volno_file) + closeout_volume_number (); exit(errors); /* NOTREACHED */ } @@ -291,9 +303,10 @@ options(argc, argv) /* Set default option values */ blocking = DEFBLOCKING; /* From Makefile */ - ar_file = getenv("TAPE"); /* From environment, or */ - if (ar_file == 0) - ar_file = DEF_AR_FILE; /* From Makefile */ + ar_files = (char **) malloc (sizeof (char *) * 10); + ar_files_len = 10; + n_ar_files = 0; + cur_ar_file = 0; /* Parse options */ while ((c = getoldopt(argc, argv, @@ -341,6 +354,10 @@ options(argc, argv) filename_terminator = '\0'; break; + case 17: + f_volno_file = optarg; + break; + case 'g': /* We are making a GNU dump; save directories at the beginning of the archive, and include in each @@ -382,7 +399,12 @@ options(argc, argv) sprintf(buf,"/dev/rmt%d",add+c-'0'); #endif - ar_file=buf; + if (n_ar_files == ar_files_len) + ar_files + = (char **) + ck_malloc (sizeof (char *) + * (ar_files_len *= 2)); + ar_files[n_ar_files++]=buf; } break; @@ -422,7 +444,12 @@ options(argc, argv) break; case 'f': /* Use ar_file for the archive */ - ar_file = optarg; + if (n_ar_files == ar_files_len) + ar_files + = (char **) ck_malloc (sizeof (char *) + * (ar_files_len *= 2)); + + ar_files[n_ar_files++] = optarg; break; case 'F': @@ -589,13 +616,25 @@ options(argc, argv) case '?': badopt: - msg("Unknown option. Use '%s +help' for a complete list of options.", tar); + msg("Unknown option. Use '%s --help' for a complete list of options.", tar); exit(EX_ARGSBAD); } } blocksize = blocking * RECORDSIZE; + if (n_ar_files == 0) + { + n_ar_files = 1; + ar_files[0] = getenv("TAPE"); /* From environment, or */ + if (ar_files[0] == 0) + ar_files[0] = DEF_AR_FILE; /* From Makefile */ + } + if (n_ar_files > 1 && !f_multivol) + { + msg ("Multiple archive files requires --multi-volume\n"); + exit (EX_ARGSBAD); + } } @@ -626,18 +665,22 @@ describe() fprintf(stdout, "\ Other options:\n\ +--atime-preserve don't change access times on dumped files\n\ -b, --block-size N block size of Nx512 bytes (default N=%d)\n", DEFBLOCKING); fputs ("\ -B, --read-full-blocks reblock as we read (for reading 4.2BSD pipes)\n\ -C, --directory DIR change to directory DIR\n\ +--checkpoint print directory names while reading the archive\n\ ", stdout); /* KLUDGE */ fprintf(stdout, "\ -f, --file [HOSTNAME:]F use archive file or device F (default %s)\n", DEF_AR_FILE); fputs("\ +--force-local archive file is local even if has a colon\n\ -F, --info-script F run script at end of each tape (implies -M)\n\ -G, --incremental create/list/extract old GNU-format incremental backup\n\ -g, --listed-incremental F create/list/extract new GNU-format incremental backup\n\ -h, --dereference don't dump symlinks; dump the files they point to\n\ -i, --ignore-zeros ignore blocks of zeros in archive (normally mean EOF)\n\ +--ignore-failed-read don't exit with non-zero status on unreadable files\n\ -k, --keep-old-files keep existing files; don't overwrite them from archive\n\ -K, --starting-file FILE begin at FILE in the archive\n\ -l, --one-file-system stay in local file system when creating an archive\n\ @@ -656,9 +699,10 @@ Other options:\n\ --preserve like -p -s\n\ ", stdout); /* KLUDGE */ fputs("\ -R, --record-number show record number within archive with each message\n\ +--remove-files remove files after adding them to the archive\n\ -s, --same-order,\n\ --preserve-order list of names to extract is sorted to match archive\n\ ---same-order create extracted files with the same ownership \n\ +--same-owner create extracted files with the same ownership \n\ -S, --sparse handle sparse files efficiently\n\ -T, --files-from F get names to extract or create from file F\n\ --null -T reads null-terminated names, disable -C\n\ @@ -929,9 +973,10 @@ addname(name) if(chdir_name[0]!='/') { char *path = ck_malloc(PATH_MAX); #if defined(__MSDOS__) || defined(USG) || defined(_POSIX_VERSION) - if(!getcwd(path,PATH_MAX)) + if(!getcwd(path,PATH_MAX)) { msg("Couldn't get current directory."); exit(EX_SYSTEM); + } #else char *getwd(); @@ -1018,7 +1063,7 @@ again: /* Regular expressions (shell globbing, actually). */ if (nlp->regexp) { - if (wildmat(p, nlp->name)) { + if (fnmatch(nlp->name, p, FNM_TARPATH) == 0) { nlp->found = 1; /* Remember it matched */ if(f_startfile) { free((void *)namelist); @@ -1128,7 +1173,7 @@ again: /* Regular expressions */ if (nlp->regexp) { - if (wildmat(p, nlp->name)) + if (fnmatch(nlp->name, p, FNM_TARPATH) == 0) return nlp; /* We got a match */ continue; } @@ -1296,7 +1341,6 @@ char *file; { FILE *fp; char buf[1024]; - extern char *rindex(); if(strcmp(file, "-")) fp=fopen(file,"r"); @@ -1340,7 +1384,7 @@ char *name; extern char *strstr(); for(n=0;n