From d53f7b23a9ef0e79d81533ffe8b6954f2082cd54 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 4 Jan 2019 12:12:59 +0100 Subject: Adding upstream version 1.8. Signed-off-by: Daniel Baumann --- zupdate.cc | 108 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 57 insertions(+), 51 deletions(-) (limited to 'zupdate.cc') diff --git a/zupdate.cc b/zupdate.cc index dcba0ec..dec65f4 100644 --- a/zupdate.cc +++ b/zupdate.cc @@ -1,5 +1,5 @@ /* Zupdate - recompress bzip2, gzip, xz files to lzip format - Copyright (C) 2013-2018 Antonio Diaz Diaz. + Copyright (C) 2013-2019 Antonio Diaz Diaz. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,14 +51,15 @@ namespace { void show_help() { - std::printf( "Zupdate recompresses files from bzip2, gzip, and xz formats to lzip format.\n" - "The originals are compared with the new files and then deleted.\n" + std::printf( "Zupdate recompresses files from bzip2, gzip, and xz formats to lzip\n" + "format. Each original is compared with the new file and then deleted.\n" "Only regular files with standard file name extensions are recompressed,\n" - "other files are ignored.\n" - "Compressed files are decompressed and then recompressed on the fly; no\n" - "temporary files are created.\n" - "The lzip format is chosen as destination because it is by far the most\n" - "appropriate for long-term data archiving.\n" + "other files are ignored. Compressed files are decompressed and then\n" + "recompressed on the fly; no temporary files are created. The lzip format\n" + "is chosen as destination because it is the most appropriate for\n" + "long-term data archiving.\n" + "\nIf no files are specified, recursive searches examine the current\n" + "working directory, and nonrecursive searches do nothing.\n" "\nIf the lzip compressed version of a file already exists, the file is\n" "skipped unless the '--force' option is given. In this case, if the\n" "comparison with the existing lzip version fails, an error is returned\n" @@ -70,21 +71,22 @@ void show_help() "recompressed (if needed), compared and deleted (if requested). Non-zero\n" "otherwise.\n" "\nOptions:\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n" - " -f, --force don't skip a file even if the .lz exists\n" - " -k, --keep keep (don't delete) input files\n" - " -l, --lzip-verbose pass a -v option to the lzip compressor\n" - " -M, --format= process only the formats in \n" - " -N, --no-rcfile don't read runtime configuration file\n" - " -q, --quiet suppress all messages\n" - " -r, --recursive operate recursively on directories\n" - " -v, --verbose be verbose (a 2nd -v gives more)\n" - " -0 .. -9 set compression level [default 9]\n" - " --bz2= set compressor and options for bzip2 format\n" - " --gz= set compressor and options for gzip format\n" - " --lz= set compressor and options for lzip format\n" - " --xz= set compressor and options for xz format\n" ); + " -h, --help display this help and exit\n" + " -V, --version output version information and exit\n" + " -f, --force don't skip a file even if the .lz exists\n" + " -k, --keep keep (don't delete) input files\n" + " -l, --lzip-verbose pass a -v option to the lzip compressor\n" + " -M, --format= process only the formats in \n" + " -N, --no-rcfile don't read runtime configuration file\n" + " -q, --quiet suppress all messages\n" + " -r, --recursive operate recursively on directories\n" + " -R, --dereference-recursive recursively follow symbolic links\n" + " -v, --verbose be verbose (a 2nd -v gives more)\n" + " -0 .. -9 set compression level [default 9]\n" + " --bz2= set compressor and options for bzip2 format\n" + " --gz= set compressor and options for gzip format\n" + " --lz= set compressor and options for lzip format\n" + " --xz= set compressor and options for xz format\n" ); show_help_addr(); } @@ -293,43 +295,43 @@ int zupdate_file( const std::string & name, const char * const lzip_name, int main( const int argc, const char * const argv[] ) { enum { bz2_opt = 256, gz_opt, lz_opt, xz_opt }; - std::string input_filename; + int recursive = 0; // 1 = '-r', 2 = '-R' std::list< std::string > filenames; std::vector< std::string > lzip_args2; // args to lzip, maybe empty bool force = false; bool keep_input_files = false; bool no_rcfile = false; - bool recursive = false; invocation_name = argv[0]; program_name = "zupdate"; const Arg_parser::Option options[] = { - { '0', 0, Arg_parser::no }, - { '1', 0, Arg_parser::no }, - { '2', 0, Arg_parser::no }, - { '3', 0, Arg_parser::no }, - { '4', 0, Arg_parser::no }, - { '5', 0, Arg_parser::no }, - { '6', 0, Arg_parser::no }, - { '7', 0, Arg_parser::no }, - { '8', 0, Arg_parser::no }, - { '9', 0, Arg_parser::no }, - { 'f', "force", Arg_parser::no }, - { 'h', "help", Arg_parser::no }, - { 'k', "keep", Arg_parser::no }, - { 'l', "lzip-verbose", Arg_parser::no }, - { 'M', "format", Arg_parser::yes }, - { 'N', "no-rcfile", Arg_parser::no }, - { 'q', "quiet", Arg_parser::no }, - { 'r', "recursive", Arg_parser::no }, - { 'v', "verbose", Arg_parser::no }, - { 'V', "version", Arg_parser::no }, - { bz2_opt, "bz2", Arg_parser::yes }, - { gz_opt, "gz", Arg_parser::yes }, - { lz_opt, "lz", Arg_parser::yes }, - { xz_opt, "xz", Arg_parser::yes }, - { 0 , 0, Arg_parser::no } }; + { '0', 0, Arg_parser::no }, + { '1', 0, Arg_parser::no }, + { '2', 0, Arg_parser::no }, + { '3', 0, Arg_parser::no }, + { '4', 0, Arg_parser::no }, + { '5', 0, Arg_parser::no }, + { '6', 0, Arg_parser::no }, + { '7', 0, Arg_parser::no }, + { '8', 0, Arg_parser::no }, + { '9', 0, Arg_parser::no }, + { 'f', "force", Arg_parser::no }, + { 'h', "help", Arg_parser::no }, + { 'k', "keep", Arg_parser::no }, + { 'l', "lzip-verbose", Arg_parser::no }, + { 'M', "format", Arg_parser::yes }, + { 'N', "no-rcfile", Arg_parser::no }, + { 'q', "quiet", Arg_parser::no }, + { 'r', "recursive", Arg_parser::no }, + { 'R', "dereference-recursive", Arg_parser::no }, + { 'v', "verbose", Arg_parser::no }, + { 'V', "version", Arg_parser::no }, + { bz2_opt, "bz2", Arg_parser::yes }, + { gz_opt, "gz", Arg_parser::yes }, + { lz_opt, "lz", Arg_parser::yes }, + { xz_opt, "xz", Arg_parser::yes }, + { 0 , 0, Arg_parser::no } }; const Arg_parser parser( argc, argv, options ); if( parser.error().size() ) // bad option @@ -355,7 +357,8 @@ int main( const int argc, const char * const argv[] ) case 'M': parse_format_list( arg ); break; case 'N': no_rcfile = true; break; case 'q': verbosity = -1; lzip_args2.push_back( "-q" ); break; - case 'r': recursive = true; break; + case 'r': recursive = 1; break; + case 'R': recursive = 2; break; case 'v': if( verbosity < 4 ) ++verbosity; break; case 'V': show_version(); return 0; case bz2_opt: parse_compressor( arg, fmt_bz2, 1 ); break; @@ -378,6 +381,9 @@ int main( const int argc, const char * const argv[] ) for( ; argind < parser.arguments(); ++argind ) filenames.push_back( parser.argument( argind ) ); + if( filenames.empty() && recursive ) filenames.push_back( "." ); + + std::string input_filename; int retval = 0; bool error = false; while( next_filename( filenames, input_filename, error, recursive, true ) ) -- cgit v1.2.3