|
|||||||||||
|
Patches for pax
From: Russell Stuart <russell(at)stuart.id.au>
Date: Tue Apr 22 2003 - 01:54:52 EDT
These patches are mostly add new features - not fix bugs. This does not seem to be the appropriate list to send so things - is there a better one? This first patch GNU'ises the pax source. Pax uses some C library routines only found on BSD, such as fgetln(). I am not using a BSD platform. I emulated most of those routines in a separate library outside of the pax source. This patch only covers the cases where that was not possible. The changed code should compile on any GNU platform. There are also a couple of bug fixes here to do with handling long (as opposed to long long) off_t's. diff -Nur pax-3.3-doc/src/ar_io.c pax-3.3-gcc/src/ar_io.c --- pax-3.3-doc/src/ar_io.c 2003-02-03 19:06:42.000000000 +1000 +++ pax-3.3-gcc/src/ar_io.c 2003-04-22 15:15:50.000000000 +1000 @@ -57,6 +57,7 @@ #include @@ -302,3 +302,12 @@ int tty_read(char *, int); void paxwarn(int, const char *, ...); void syswarn(int, int, const char *, ...); + +/* + * Handle printing of offsets. + */ +#ifdef LONG_OFF_T +#define FMT_OFF "l" +#else +#define FMT_OFF "q" +#endif diff -Nur pax-3.3-doc/src/gen_subs.c pax-3.3-gcc/src/gen_subs.c --- pax-3.3-doc/src/gen_subs.c 2002-10-17 05:20:02.000000000 +1000 +++ pax-3.3-gcc/src/gen_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -56,6 +56,7 @@ #include @@ -76,7 +76,7 @@ static void printflg(unsigned int); static int c_frmt(const void *, const void *); static off_t str_offt(char *); -static char *getline(FILE *fp); +static char *getln(FILE *fp); static void pax_options(int, char **); static void pax_usage(void); static void tar_options(int, char **); @@ -87,7 +87,7 @@ /* errors from getline */ #define GETLINE_FILE_CORRUPT 1 #define GETLINE_OUT_OF_MEM 2 -static int getline_error; +static int getln_error;
#define GZIP_CMD "gzip" /* command to run as gzip */
+/* + * getln() + * read a line and return it in a malloc'ed buffer. + * + * In pax 3.0 this was called my_getline(). somewhere + * between 3.0 and 3.3 it was replaced with a function + * called getline() that did the same thing as my_getline() + * but used fgetln(). fgetln() is not a GNU function - its + * only available on BSD, and that made life difficult. + * Very difficult in fact, as the easiy way to emulate + * fgetln() is to use the GNU getline() function, buts its + * name clashed with the one defined here. This third + * re-write is shorter and faster than the previous two, + * and is compatible with GNU libc. + */ char * -getline(FILE *f) +getln(FILE * f) {
- char *name, *temp;
+ char *name = 0;
+ size_t buflen = 0;
size_t len;
- name = fgetln(f, &len);
- if (!name) {
- getline_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0;
+ len = getline(&name, &buflen, f);
+ if (len == (size_t)-1) {
+ if (name)
+ free(name);
+ getln_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0;
return(0);
}
- if (name[len-1] != '\n')
- len++;
- temp = malloc(len);
- if (!temp) {
- getline_error = GETLINE_OUT_OF_MEM;
- return(0);
- }
- memcpy(temp, name, len-1);
- temp[len-1] = 0;
- return(temp);
+ if (name[len - 1] == '\n')
+ name[len - 1] = '\0';
+ return name;
} - + /* * no_op() * for those option functions where the archive format has nothing to do. diff -Nur pax-3.3-doc/src/pax.c pax-3.3-gcc/src/pax.c --- pax-3.3-doc/src/pax.c 2002-10-17 05:20:02.000000000 +1000 +++ pax-3.3-gcc/src/pax.c 2003-04-22 15:15:50.000000000 +1000 @@ -56,6 +56,7 @@ #include This second patch replaces a patch I sent earlier (on 2003-03-21). The patch adds a -M option that causes pax/cpio/tar to treat files being modified or deleted as they are copied as warning rather than an error. A warning message it still issued, but the exit status remains at 0. The earlier version of the patch did not handle file deletion. The rational for the patch is that I use pax to backup entire file systems and there are some files that are modified during the copy - typically log files and such. I want those files backed up and I don't care if I miss a few lines at the end, and I don't care they are deleted before pax gets to them (happens during log file rotation). So pax having a non-zero exit status because the file system was modified while during the copy is less than helpful. When the -M flag is given the non-zero exit status is reserved for something really going wrong - like a write error. There is also a patch in here to make the pax version of cpio behave like the real cpio. The real cpio does not exit immediately if passed a filename on stdin that does not exist. Instead it behaves like pax (when invoked as pax) does - it ignores the problem file and has a non zero exit status. I did this primarily because it makes the rest of the stuff I did easier, but I think it should be behave like that regardless. diff -Nur pax-3.3-gcc/src/ar_io.c pax-3.3-modifyWarn/src/ar_io.c --- pax-3.3-gcc/src/ar_io.c 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-modifyWarn/src/ar_io.c 2003-04-22 15:15:50.000000000 +1000 @@ -492,8 +492,9 @@ if (!invld_rec) return(0); - paxwarn(1,"Cannot append, device record size %d does not support %s spec", - rdblksz, argv0); + paxwarn(1, + "Cannot append, device record size %d does not support %s spec", + rdblksz, argv0); return(-1); } diff -Nur pax-3.3-gcc/src/ar_subs.c pax-3.3-modifyWarn/src/ar_subs.c --- pax-3.3-gcc/src/ar_subs.c 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-modifyWarn/src/ar_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -594,7 +594,7 @@ /* * wr_rdfile() * fill write buffer with the contents of a file. We are passed an open - * file descriptor to the file an the archive structure that describes the + * file descriptor to an archive structure that describes the * file we are storing. The variable "left" is modified to contain the * number of bytes of the file we were NOT able to write to the archive. * it is important that we always write EXACTLY the number of bytes that @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm cpio .Fl o -.Op Fl aABcLvzZ +.Op Fl aABcLMvzZ .Op Fl C Ar bytes .Op Fl F Ar archive .Op Fl H Ar format @@ -58,7 +58,7 @@ .Op Ar "< archive" .Nm cpio .Fl p -.Op Fl adlLmuv +.Op Fl adlLmMuv .Ar destination-directory .Ar "< name-list" .Sh DESCRIPTION @@ -117,6 +117,8 @@ .El .It Fl L Follow symbolic links. +.It Fl M +Do not treat files being modified or deleted during the copy as an error. .It Fl v Be verbose about operations. List filenames as they are written to the archive. @@ -255,7 +257,9 @@ find a file while writing an archive, or cannot preserve the user ID, group ID, file mode, or access and modification times when the .Fl p -option is specified, a diagnostic message is written to standard +option is specified, or a file is modified or deleted when the +.Fl M +option is not specified, a diagnostic message is written to standarderror and a non-zero exit value will be returned, but processing will continue. In the case where diff -Nur pax-3.3-gcc/src/extern.h pax-3.3-modifyWarn/src/extern.h --- pax-3.3-gcc/src/extern.h 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-modifyWarn/src/extern.h 2003-04-22 15:15:50.000000000 +1000 @@ -223,6 +223,7 @@ extern int Dflag; extern int Hflag; extern int Lflag; +extern int Mflag; extern int Xflag; extern int Yflag; extern int Zflag; diff -Nur pax-3.3-gcc/src/file_subs.c pax-3.3-modifyWarn/src/file_subs.c --- pax-3.3-gcc/src/file_subs.c 2003-02-03 19:06:43.000000000 +1000 +++ pax-3.3-modifyWarn/src/file_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -1574,7 +1608,7 @@ void tar_usage(void) {
- (void)fputs("usage: tar [-]{crtux}[-befhmopqsvwzHLOPXZ014578] [blocksize] ",
+ (void)fputs("usage: tar [-]{crtux}[-befhmopqsvwzHLMOPXZ014578] [blocksize] ",
stderr);
(void)fputs("[archive] [replstr] [-C directory] [-I file] [file ...]\n",
stderr);
@@ -1589,10 +1623,10 @@ void cpio_usage(void) {
- (void)fputs("usage: cpio -o [-aABcLvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr);
+ (void)fputs("usage: cpio -o [-aABcLMvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr);
(void)fputs(" [-F archive] < name-list [> archive]\n", stderr);
(void)fputs(" cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr);
(void)fputs(" [-I archive] [-F archive] [pattern...] [< archive]\n", stderr);
- (void)fputs(" cpio -p [-adlLmuvV] destination-directory < name-list\n", stderr);
+ (void)fputs(" cpio -p [-adlLmMuvV] destination-directory < name-list\n", stderr);
exit(1);
} diff -Nur pax-3.3-gcc/src/options.h pax-3.3-modifyWarn/src/options.h --- pax-3.3-gcc/src/options.h 1996-06-24 00:20:37.000000000 +1000 +++ pax-3.3-modifyWarn/src/options.h 2003-04-22 15:15:50.000000000 +1000
/*
-#define BDEXTR (AF|BF|LF|TF|WF|XF|CBF|CHF|CLF|CPF|CXF) +#define BDEXTR (AF|BF|LF|TF|WF|XF|CBF|CHF|CLF|CMF|CPF|CXF) #define BDARCH (CF|KF|LF|NF|PF|RF|CDF|CEF|CYF|CZF) #define BDCOPY (AF|BF|FF|OF|XF|CBF|CEF) -#define BDLIST (AF|BF|IF|KF|LF|OF|PF|RF|TF|UF|WF|XF|CBF|CDF|CHF|CLF|CPF|CXF|CYF|CZF) +#define BDLIST (AF|BF|IF|KF|LF|OF|PF|RF|TF|UF|WF|XF|CBF|CDF|CHF|CLF|CMF|CPF|CXF|CYF|CZF) diff -Nur pax-3.3-gcc/src/pax.1 pax-3.3-modifyWarn/src/pax.1 --- pax-3.3-gcc/src/pax.1 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-modifyWarn/src/pax.1 2003-04-22 15:15:50.000000000 +1000 @@ -109,7 +109,7 @@ .Op Ar pattern ... .Nm pax .Fl w -.Op Fl dituvzHLPX +.Op Fl dituvzHLMPX .Bk -words .Op Fl b Ar blocksize .Ek @@ -835,6 +835,8 @@ system traversal. .It Fl L Follow all symbolic links to perform a logical file system traversal. +.It Fl M +Do not treat files being modified or deleted during the copy as an error. .It Fl O Force the archive to be one volume. If a volume ends prematurely, @@ -1123,8 +1125,11 @@ find a file when writing an archive, or cannot preserve the user ID, group ID, or file mode when the .Fl p -option is specified, a diagnostic message is written to standard error -and a non-zero exit status will be returned, but processing will continue. +option is specified, or a file is modified or deleted when the +.Fl M +option is not specified, a diagnostic message is written to standard +error and a non-zero exit status will be returned, but processing +will continue. In the case where .Nm cannot create a link to a file, @@ -1175,6 +1180,7 @@ .Fl G , .Fl H , .Fl L , +.Fl M , .Fl O , .Fl P , .Fl T , diff -Nur pax-3.3-gcc/src/pax.c pax-3.3-modifyWarn/src/pax.c --- pax-3.3-gcc/src/pax.c 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-modifyWarn/src/pax.c 2003-04-22 15:15:50.000000000 +1000 @@ -39,7 +39,7 @@
.Sh SYNOPSIS
.Nm tar
.Sm off
-.Oo \&- Oc {crtux} Op befhmopqsvwzHLOPXZ014578
+.Oo \&- Oc {crtux} Op befhmopqsvwzHLMOPXZ014578
.Sm on
.Op Ar blocksize
.Op Ar archive
@@ -208,6 +208,8 @@ In extract mode this means that a directory entry in the archive will not overwrite an existing symbolic link, but rather what the link ultimately points to. +.It Fl M +Do not treat files being modified or deleted during the copy as an error. .It Fl P Do not strip leading slashes .Pq Sq / @@ -282,7 +284,9 @@ find a file while writing an archive, or cannot preserve the user ID, group ID, file mode, or access and modification times when the .Fl p -option is specified, a diagnostic message is written to standard +option is specified, or a file is modified or deleted when the +.Fl M +option is not specified, a diagnostic message is written to standarderror and a non-zero exit value will be returned, but processing will continue. In the case where @@ -330,6 +334,8 @@ .Sh CAVEATS The .Fl L -flag is not portable to other versions of +and +.Fl M +flags are not portable to other versions of.Nm -where it may have a different meaning. +where they may have a different meaning. diff -Nur pax-3.3-gcc/src/tty_subs.c pax-3.3-modifyWarn/src/tty_subs.c --- pax-3.3-gcc/src/tty_subs.c 2003-03-05 06:27:58.000000000 +1000 +++ pax-3.3-modifyWarn/src/tty_subs.c 2003-04-22 15:15:50.000000000 +1000 @@ -142,19 +142,17 @@ } /* - * paxwarn() - * write a warning message to stderr. if "set" the exit value of pax - * will be non-zero. + * vsyswarn() + * write a warning message to stderr. If the parameter "set" is: + * 0 the exit value of pax will unaffected. + * 1 the exit value of pax will be non-zero. + * 2 the exit value of pax be non-zero if the -M flag has been given, + * otherwise the exit value is uneffected and a warning is printed. */
-void
- va_list ap; - - va_start(ap, fmt); - if (set) - exit_val = 1; /* * when vflag we better ship out an extra \n to get this message on a * line by itself }
/*
+ * paxwarn()
+ * Shorthand interface to vsyswarn() above.
+ */
+
+void
+paxwarn(int set, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsyswarn(set, 0, fmt, ap);
+ va_end(ap);
+}
+ +/* * syswarn() - * write a warning message to stderr. if "set" the exit value of pax - * will be non-zero. + * Shorthand interface to vsyswarn() above. */
void
va_list ap;
va_start(ap, fmt);
- if (set)
- exit_val = 1;
- /*
- * when vflag we better ship out an extra \n to get this message on a
- * line by itself
- */
- if (vflag && vfpart) {
- (void)fflush(listf);
- (void)fputc('\n', stderr);
- vfpart = 0;
- }
- (void)fprintf(stderr, "%s: ", argv0);
- (void)vfprintf(stderr, fmt, ap);
+ vsyswarn(set, errnum, fmt, ap);
va_end(ap);
-
- /*
- * format and print the errno
- */
- if (errnum > 0)
- (void)fprintf(stderr, ": %s", strerror(errnum));
- (void)fputc('\n', stderr);
} This patch adds a -j switch to pax, which causes it to compress / decompress using bzip2. This is the same as GNU tar. diff -Nur pax-3.3-modifyWarn/src/cpio.1 pax-3.3-bzip2/src/cpio.1 --- pax-3.3-modifyWarn/src/cpio.1 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-bzip2/src/cpio.1 2003-04-22 15:15:50.000000000 +1000 @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm cpio .Fl o -.Op Fl aABcLMvzZ +.Op Fl aABcjLMvzZ .Op Fl C Ar bytes .Op Fl F Ar archive .Op Fl H Ar format @@ -48,7 +48,7 @@ .Op Ar "> archive" .Nm cpio .Fl i -.Op Fl bBcdfmrsStuvzZ6 +.Op Fl bBcdfjmrsStuvzZ6 .Op Fl C Ar bytes .Op Fl E Ar file .Op Fl F Ar archive @@ -115,6 +115,10 @@ .It Ar ustar POSIX ustar format. .El +.It Fl j +Compress or decompress archive using +.Xr bzip2 1 +format. .It Fl L Follow symbolic links. .It Fl M @@ -123,7 +127,7 @@ Be verbose about operations. List filenames as they are written to the archive. .It Fl z -Compress archive using +Compress or decompress archive using .Xr gzip 1 format. .It Fl Z diff -Nur pax-3.3-modifyWarn/src/options.c pax-3.3-bzip2/src/options.c --- pax-3.3-modifyWarn/src/options.c 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-bzip2/src/options.c 2003-04-22 15:15:50.000000000 +1000 @@ -92,6 +92,7 @@ #define GZIP_CMD "gzip" /* command to run as gzip */ #define COMPRESS_CMD "compress" /* command to run as compress */ +#define BZIP2_CMD "bzip2" /* command to run as bzip2 */ /* * Format specific routine table - MUST BE IN SORTED ORDER BY NAME @@ -1574,18 +1593,18 @@ void pax_usage(void) {
- (void)fputs("usage: pax [-cdnvzO] [-E limit] [-f archive] ", stderr);
+ (void)fputs("usage: pax [-cdjnvzO] [-E limit] [-f archive] ", stderr);
(void)fputs("[-s replstr] ... [-U user] ...", stderr);
(void)fputs("\n [-G group] ... ", stderr);
(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
(void)fputs("[pattern ...]\n", stderr);
- (void)fputs(" pax -r [-cdiknuvzDOYZ] [-E limit] ", stderr);
+ (void)fputs(" pax -r [-cdijknuvzDOYZ] [-E limit] ", stderr);
(void)fputs("[-f archive] [-o options] ... \n", stderr);
(void)fputs(" [-p string] ... [-s replstr] ... ", stderr);
(void)fputs("[-U user] ... [-G group] ...\n ", stderr);
(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
(void)fputs(" [pattern ...]\n", stderr);
- (void)fputs(" pax -w [-dituvzHLMOPX] [-b blocksize] ", stderr);
+ (void)fputs(" pax -w [-dijtuvzHLMOPX] [-b blocksize] ", stderr);
(void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr);
(void)fputs(" [-B bytes] [-s replstr] ... ", stderr);
(void)fputs("[-o options] ... [-U user] ...", stderr);
@@ -1608,7 +1627,7 @@ void tar_usage(void) {
- (void)fputs("usage: tar [-]{crtux}[-befhmopqsvwzHLMOPXZ014578] [blocksize] ",
+ (void)fputs("usage: tar [-]{crtux}[-befhjmopqsvwzHLMOPXZ014578] [blocksize] ",
stderr);
(void)fputs("[archive] [replstr] [-C directory] [-I file] [file ...]\n",
stderr);
@@ -1623,9 +1642,9 @@ void cpio_usage(void) {
- (void)fputs("usage: cpio -o [-aABcLMvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr);
+ (void)fputs("usage: cpio -o [-aABcjLMvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr);
(void)fputs(" [-F archive] < name-list [> archive]\n", stderr);
- (void)fputs(" cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr);
+ (void)fputs(" cpio -i [-bBcdfjmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr);
(void)fputs(" [-I archive] [-F archive] [pattern...] [< archive]\n", stderr);
(void)fputs(" cpio -p [-adlLmMuvV] destination-directory < name-list\n", stderr);
exit(1);
diff -Nur pax-3.3-modifyWarn/src/pax.1 pax-3.3-bzip2/src/pax.1
--- pax-3.3-modifyWarn/src/pax.1 2003-04-22 15:15:50.000000000 +1000
+++ pax-3.3-bzip2/src/pax.1 2003-04-22 15:15:50.000000000 +1000
@@ -46,7 +46,7 @@ .Nd read and write file archives and copy directory hierarchies .Sh SYNOPSIS .Nm pax -.Op Fl cdnvz +.Op Fl cdjnvz .Bk -words .Op Fl f Ar archive .Ek @@ -73,7 +73,7 @@ .Op Ar pattern ... .Nm pax .Fl r -.Op Fl cdiknuvzDYZ +.Op Fl cdijknuvzDYZ .Bk -words .Op Fl f Ar archive .Ek @@ -109,7 +109,7 @@ .Op Ar pattern ... .Nm pax .Fl w -.Op Fl dituvzHLMPX +.Op Fl dijtuvzHLMPX .Bk -words .Op Fl b Ar blocksize .Ek @@ -467,6 +467,12 @@ is encountered when reading a response or if .Pa /dev/tty cannot be opened for reading and writing. +.It Fl z +Use +.Xr bzip2 1 +to compress (decompress) the archive while writing (reading). +Incompatible with +.Fl a . .It Fl k Do not overwrite existing files. .It Fl l @@ -1174,6 +1180,7 @@ .St -p1003.2 standard. The options +.Fl j , .Fl B , .Fl D , .Fl E , diff -Nur pax-3.3-modifyWarn/src/tar.1 pax-3.3-bzip2/src/tar.1 --- pax-3.3-modifyWarn/src/tar.1 2003-04-22 15:15:50.000000000 +1000 +++ pax-3.3-bzip2/src/tar.1 2003-04-22 15:15:50.000000000 +1000 @@ -39,7 +39,7 @@
.Sh SYNOPSIS
.Nm tar
.Sm off
-.Oo \&- Oc {crtux} Op befhmopqsvwzHLMOPXZ014578
+.Oo \&- Oc {crtux} Op befhjmopqsvwzHLMOPXZ014578
.Sm on
.Op Ar blocksize
.Op Ar archive
@@ -111,6 +111,10 @@ In extract mode this means that a directory entry in the archive will not overwrite an existing symbolic link, but rather what the link ultimately points to. +.It Fl j +Compress or decompress archive using +.Xr bzip2 1 +format. .It Fl m Do not preserve modification time. .It Fl O @@ -194,7 +198,9 @@ to prompt the user for the filename to use when storing or extracting files in an archive. .It Fl z -Compress archive using gzip. +Compress or decompress archive using +.Xr gzip 1 +format. .It Fl C Ar directory This is a positional argument which sets the working directory for the following files. @@ -333,6 +339,7 @@ .At v7 . .Sh CAVEATS The +.Fl j , .Fl L and .Fl M This final patch fixes a couple of minor errors in the man page. It is similar to a Red Hat patch to pax. diff -Nur pax-3.3.orig/src/pax.1 pax-3.3-doc/src/pax.1 --- pax-3.3.orig/src/pax.1 2003-03-13 06:12:35.000000000 +1000 +++ pax-3.3-doc/src/pax.1 2003-04-22 15:15:50.000000000 +1000 @@ -720,7 +720,7 @@ .It Ar tar The old BSD tar format as found in BSD4.3. The default blocksize for this format is 10240 bytes. -Pathnames stored by this format must be 100 characters or less in length. +Pathnames stored by this format must be 99 characters or less in length. Only .Em regular files, @@ -738,7 +738,9 @@ .St -p1003.2 standard. The default blocksize for this format is 10240 bytes. -Pathnames stored by this format must be 250 characters or less in length. +Filenames stored by this format, not including the directory prefix, can +not be more than 99 characters in length. The directory prefix can not be +more than 155 characters in length. .El .Pp .Nm -- Regards, Russell StuartReceived on Tue Apr 22 01:57:18 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:29:54 EDT |
||||||||||
|
|||||||||||