On 11/07/2012 04:30 AM, Live user wrote:
John Stanley wrote:
Hi,
I was wondering if it would be possible in the 'skip-old-files' option
warning messages, to have a distinction made between existing files and
existing directories, i.e., instead of, e.g., printing:
tar: ./usr/local: skipping existing file
print:
tar: ./usr/local/: skipping existing directory
This would make it much easier to parse existing files and existing
directories. I have been using the following simple patch to handle
this in my work:
+++ tar-master-1.26.90.new/src/extract.c 2012-11-06
18:18:28.853013706 -0500
@@ -644,8 +644,12 @@ maybe_recoverable (char *file_name, bool
switch (old_files_option)
{
case SKIP_OLD_FILES:
- WARNOPT (WARN_EXISTING_FILE,
- (0, 0, _("%s: skipping existing file"), file_name));
+ if (current_stat_info.had_trailing_slash)
+ WARNOPT (WARN_EXISTING_FILE,
+ (0, 0, _("%s/: skipping existing directory"),
file_name));
+ else
+ WARNOPT (WARN_EXISTING_FILE,
+ (0, 0, _("%s: skipping existing file"),
file_name));
return RECOVER_SKIP;
case KEEP_OLD_FILES:
Directories don't always have trailing slash in tar archives, so you should
check for both the trailing slash or the directory attribute.
How about something along these lines:
--- tar-1.26.old/src/extract.c 2010-11-27 05:33:22.000000000 -0500
+++ tar-1.26.new/src/extract.c 2012-11-07 06:50:07.210023821 -0500
@@ -639,9 +639,18 @@ maybe_recoverable (char *file_name, bool
switch (old_files_option)
{
- case KEEP_OLD_FILES:
+ case SKIP_OLD_FILES:
+ if (S_ISDIR(current_stat_info.stat.st_mode))
+ WARNOPT (WARN_EXISTING_FILE,
+ (0, 0, _("%s/: skipping existing directory"),
file_name));
+ else
+ 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, ¤t_stat_info))
break;
@@ -1351,6 +1360,7 @@ prepare_to_extract (char const *file_nam
case DIRTYPE:
case GNUTYPE_DUMPDIR:
+ current_stat_info.stat.st_mode |= S_IFDIR;
*fun = extract_dir;
if (current_stat_info.is_dumpdir)
delay_directory_restore_option = true;