]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge r203183 from svn.freebsd.org: Support -V option as in GNU cpio.
authorTim Kientzle <kientzle@gmail.com>
Mon, 1 Feb 2010 03:28:17 +0000 (22:28 -0500)
committerTim Kientzle <kientzle@gmail.com>
Mon, 1 Feb 2010 03:28:17 +0000 (22:28 -0500)
Submitted by: Philip Kizer

SVN-Revision: 1849

cpio/cmdline.c
cpio/cpio.c
cpio/cpio.h

index 2223798c124daa93d29f1d8fb7871a31c924f214..0e18f9f423d4dacccbd1d09d38bc895f2a42f869 100644 (file)
@@ -51,7 +51,7 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cmdline.c,v 1.5 2008/12/06 07:30:40 kientzl
 /*
  * Short options for cpio.  Please keep this sorted.
  */
-static const char *short_options = "0AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuvW:yZz";
+static const char *short_options = "0AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuVvW:yZz";
 
 /*
  * Long options for cpio.  Please keep this sorted.
@@ -62,6 +62,7 @@ static const struct option {
        int equivalent; /* Equivalent short option. */
 } cpio_longopts[] = {
        { "create",                     0, 'o' },
+       { "dot",                        0, 'V' },
        { "extract",                    0, 'i' },
        { "file",                       1, 'F' },
        { "format",                     1, 'H' },
index 7d5031bbcd8fc7477048947e717416547133ea93..cab7f01d889158f4c0830c5dcd6198a124cdd066 100644 (file)
@@ -296,6 +296,9 @@ main(int argc, char *argv[])
                case 'v': /* POSIX 1997 */
                        cpio->verbose++;
                        break;
+               case 'V': /* GNU cpio */
+                       cpio->dot++;
+                       break;
                case OPTION_VERSION: /* GNU convention */
                        version();
                        break;
@@ -339,6 +342,9 @@ main(int argc, char *argv[])
        /* -l requires -p */
        if (cpio->option_link && cpio->mode != 'p')
                lafe_errc(1, 0, "Option -l requires -p");
+       /* -v overrides -V */
+       if (cpio->dot && cpio->verbose)
+               cpio->dot = 0;
        /* TODO: Flag other nonsensical combinations. */
 
        switch (cpio->mode) {
@@ -396,7 +402,7 @@ static const char *long_help_msg =
        "First option must be a mode specifier:\n"
        "  -i Input  -o Output  -p Pass\n"
        "Common Options:\n"
-       "  -v    Verbose\n"
+       "  -v Verbose filenames     -V  one dot per file\n"
        "Create: %p -o [options]  < [list of files] > [archive]\n"
        "  -J,-y,-z,--lzma  Compress archive with xz/bzip2/gzip/lzma\n"
        "  --format {odc|newc|ustar}  Select archive format\n"
@@ -527,6 +533,8 @@ mode_out(struct cpio *cpio)
        }
 
        r = archive_write_close(cpio->archive);
+       if (cpio->dot)
+               fprintf(stderr, "\n");
        if (r != ARCHIVE_OK)
                lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
 
@@ -646,6 +654,8 @@ entry_to_archive(struct cpio *cpio, struct archive_entry *entry)
        /* Print out the destination name to the user. */
        if (cpio->verbose)
                fprintf(stderr,"%s", destpath);
+       if (cpio->dot)
+               fprintf(stderr, ".");
 
        /*
         * Option_link only makes sense in pass mode and for
@@ -839,7 +849,9 @@ mode_in(struct cpio *cpio)
                if (destpath == NULL)
                        continue;
                if (cpio->verbose)
-                       fprintf(stdout, "%s\n", destpath);
+                       fprintf(stderr, "%s\n", destpath);
+               if (cpio->dot)
+                       fprintf(stderr, ".");
                if (cpio->uid_override >= 0)
                        archive_entry_set_uid(entry, cpio->uid_override);
                if (cpio->gid_override >= 0)
@@ -856,6 +868,8 @@ mode_in(struct cpio *cpio)
                }
        }
        r = archive_read_close(a);
+       if (cpio->dot)
+               fprintf(stderr, "\n");
        if (r != ARCHIVE_OK)
                lafe_errc(1, 0, "%s", archive_error_string(a));
        r = archive_write_close(ext);
@@ -1065,6 +1079,8 @@ mode_pass(struct cpio *cpio, const char *destdir)
 
        archive_entry_linkresolver_free(cpio->linkresolver);
        r = archive_write_close(cpio->archive);
+       if (cpio->dot)
+               fprintf(stderr, "\n");
        if (r != ARCHIVE_OK)
                lafe_errc(1, 0, "%s", archive_error_string(cpio->archive));
 
index 3eed83494b8eafbf013ea1fcc28b700dc4206581..7917339cb32be2e8ff1fbf5099282abcd6a57147 100644 (file)
@@ -52,6 +52,7 @@ struct cpio {
        const char       *format; /* -H format */
        int               bytes_per_block; /* -b block_size */
        int               verbose;   /* -v */
+       int               dot;  /* -V */
        int               quiet;   /* --quiet */
        int               extract_flags; /* Flags for extract operation */
        char              symlink_mode; /* H or L, per BSD conventions */