Fix --keep-old-files option.

The regression was introduced by 8f390db9.  This patch implements additional
option --skip-old-files, which silently skips members which would cause
writing over existing files, and restores --keep-old-files to its traditional
behavior.

* NEWS: Update.
* configure.ac: Update.
* doc/tar.texi: Document the changes.
* src/common.h (SKIP_OLD_FILES): New old_files mode.
* src/extract.c (maybe_recoverable): Restore KEEP_OLD_FILES behavior.
Handle SKIP_OLD_FILES.
* src/tar.c: New option --skip-old-files.
* tests/extrac18.at: New file.
* tests/extrac19.at: New file.
* tests/Makefile.am: Add new test cases.
* tests/testsuite.at: Likewise.
This commit is contained in:
Sergey Poznyakoff
2011-11-26 15:50:40 +02:00
parent 02bf3a96a9
commit 7a5a3708cb
10 changed files with 209 additions and 27 deletions
+1
View File
@@ -183,6 +183,7 @@ enum old_files
OVERWRITE_OLD_FILES, /* --overwrite */
UNLINK_FIRST_OLD_FILES, /* --unlink-first */
KEEP_OLD_FILES, /* --keep-old-files */
SKIP_OLD_FILES, /* --skip-old-files */
KEEP_NEWER_FILES /* --keep-newer-files */
};
GLOBAL enum old_files old_files_option;
+4 -1
View File
@@ -642,11 +642,14 @@ maybe_recoverable (char *file_name, bool regular, bool *interdir_made)
switch (old_files_option)
{
case KEEP_OLD_FILES:
case SKIP_OLD_FILES:
WARNOPT (WARN_EXISTING_FILE,
(0, 0, _("%s: skipping existing file"), file_name));
return RECOVER_SKIP;
case KEEP_OLD_FILES:
return RECOVER_NO;
case KEEP_NEWER_FILES:
if (file_newer_p (file_name, stp, &current_stat_info))
break;
+11 -2
View File
@@ -328,6 +328,7 @@ enum
SHOW_DEFAULTS_OPTION,
SHOW_OMITTED_DIRS_OPTION,
SHOW_TRANSFORMED_NAMES_OPTION,
SKIP_OLD_FILES_OPTION,
SPARSE_VERSION_OPTION,
STRIP_COMPONENTS_OPTION,
SUFFIX_OPTION,
@@ -452,7 +453,11 @@ static struct argp_option options[] = {
{"remove-files", REMOVE_FILES_OPTION, 0, 0,
N_("remove files after adding them to the archive"), GRID+1 },
{"keep-old-files", 'k', 0, 0,
N_("don't replace existing files when extracting"), GRID+1 },
N_("don't replace existing files when extracting, "
"treat them as errors"), GRID+1 },
{"skip-old-files", SKIP_OLD_FILES_OPTION, 0, 0,
N_("don't replace existing files when extracting, silently skip over them"),
GRID+1 },
{"keep-newer-files", KEEP_NEWER_FILES_OPTION, 0, 0,
N_("don't replace existing files that are newer than their archive copies"), GRID+1 },
{"overwrite", OVERWRITE_OPTION, 0, 0,
@@ -1544,7 +1549,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
/* Don't replace existing files. */
old_files_option = KEEP_OLD_FILES;
break;
case 'K':
starting_file_option = true;
addname (arg, 0, true, NULL);
@@ -1674,6 +1679,10 @@ parse_opt (int key, char *arg, struct argp_state *state)
sparse_option = true;
break;
case SKIP_OLD_FILES_OPTION:
old_files_option = SKIP_OLD_FILES;
break;
case SPARSE_VERSION_OPTION:
sparse_option = true;
{