Support -V option to print a dot for each file processed.

Also, change the existing -vi behavior to send the filenames to
stderr rather than stdout, as GNU cpio does.

PR:             bin/141175
Submitted by:	Philip Kizer
MFC after:	14 days
This commit is contained in:
Tim Kientzle 2010-01-30 06:49:18 +00:00
parent eb0a7e4130
commit 378b2ffde5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=203183
3 changed files with 21 additions and 3 deletions

View File

@ -50,7 +50,7 @@ __FBSDID("$FreeBSD$");
/*
* Short options for cpio. Please keep this sorted.
*/
static const char *short_options = "0AaBC:F:O:cdE:f:H:hijLlmnopR:rtuvW:yZz";
static const char *short_options = "0AaBC:F:O:cdE:f:H:hijLlmnopR:rtuvVW:yZz";
/*
* Long options for cpio. Please keep this sorted.
@ -61,6 +61,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' },

View File

@ -278,6 +278,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;
@ -331,6 +334,9 @@ main(int argc, char *argv[])
/* -l requires -p */
if (cpio->option_link && cpio->mode != 'p')
cpio_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) {
@ -388,7 +394,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"
#ifdef HAVE_BZLIB_H
" -y Compress archive with bzip2\n"
@ -521,6 +527,8 @@ mode_out(struct cpio *cpio)
}
r = archive_write_close(cpio->archive);
if (cpio->dot)
fprintf(stderr, "\n");
if (r != ARCHIVE_OK)
cpio_errc(1, 0, archive_error_string(cpio->archive));
@ -659,6 +667,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
@ -857,7 +867,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)
@ -872,6 +884,8 @@ mode_in(struct cpio *cpio)
}
}
r = archive_read_close(a);
if (cpio->dot)
fprintf(stderr, "\n");
if (r != ARCHIVE_OK)
cpio_errc(1, 0, archive_error_string(a));
r = archive_write_close(ext);
@ -1078,6 +1092,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)
cpio_errc(1, 0, archive_error_string(cpio->archive));

View 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 */