浏览代码

New option --check-links.
Changed semantics of -o to comply to UNIX98 when extracting and
to its previous semantics otherwise.
(main): Call check_links if --check-links. was given.

Sergey Poznyakoff 22 年之前
父节点
当前提交
d52a1bb366
共有 1 个文件被更改,包括 43 次插入7 次删除
  1. 43 7
      src/tar.c

+ 43 - 7
src/tar.c

@@ -195,6 +195,7 @@ static struct option long_options[] =
   {"bzip2", no_argument, 0, 'j'},
   {"bzip2", no_argument, 0, 'j'},
   {"catenate", no_argument, 0, 'A'},
   {"catenate", no_argument, 0, 'A'},
   {"checkpoint", no_argument, 0, CHECKPOINT_OPTION},
   {"checkpoint", no_argument, 0, CHECKPOINT_OPTION},
+  {"check-links", no_argument, &check_links_option, 1},
   {"compare", no_argument, 0, 'd'},
   {"compare", no_argument, 0, 'd'},
   {"compress", no_argument, 0, 'Z'},
   {"compress", no_argument, 0, 'Z'},
   {"concatenate", no_argument, 0, 'A'},
   {"concatenate", no_argument, 0, 'A'},
@@ -285,7 +286,7 @@ static struct option long_options[] =
   {"volno-file", required_argument, 0, VOLNO_FILE_OPTION},
   {"volno-file", required_argument, 0, VOLNO_FILE_OPTION},
   {"wildcards", no_argument, 0, WILDCARDS_OPTION},
   {"wildcards", no_argument, 0, WILDCARDS_OPTION},
   {"wildcards-match-slash", no_argument, 0, WILDCARDS_MATCH_SLASH_OPTION},
   {"wildcards-match-slash", no_argument, 0, WILDCARDS_MATCH_SLASH_OPTION},
-
+  
   {0, 0, 0, 0}
   {0, 0, 0, 0}
 };
 };
 
 
@@ -388,7 +389,7 @@ Device blocking:\n\
 Archive format selection:\n\
 Archive format selection:\n\
   -V, --label=NAME                   create archive with volume name NAME\n\
   -V, --label=NAME                   create archive with volume name NAME\n\
               PATTERN                at list/extract time, a globbing PATTERN\n\
               PATTERN                at list/extract time, a globbing PATTERN\n\
-  -o, --old-archive, --portability   write a V7 format archive\n\
+      --old-archive, --portability   write a V7 format archive\n\
       --posix                        write a POSIX format archive\n\
       --posix                        write a POSIX format archive\n\
   -j, --bzip2                        filter the archive through bzip2\n\
   -j, --bzip2                        filter the archive through bzip2\n\
   -z, --gzip, --ungzip               filter the archive through gzip\n\
   -z, --gzip, --ungzip               filter the archive through gzip\n\
@@ -435,6 +436,7 @@ Informative output:\n\
       --version         print tar program version number, then exit\n\
       --version         print tar program version number, then exit\n\
   -v, --verbose         verbosely list files processed\n\
   -v, --verbose         verbosely list files processed\n\
       --checkpoint      print directory names while reading the archive\n\
       --checkpoint      print directory names while reading the archive\n\
+      --check-links     print a message if not all links are dumped\n\
       --totals          print total bytes written while creating archive\n\
       --totals          print total bytes written while creating archive\n\
       --index-file=FILE send verbose output to FILE\n\
       --index-file=FILE send verbose output to FILE\n\
   -R, --block-number    show block number within archive with each message\n\
   -R, --block-number    show block number within archive with each message\n\
@@ -443,6 +445,13 @@ Informative output:\n\
 	     stdout);
 	     stdout);
       fputs (_("\
       fputs (_("\
 \n\
 \n\
+Compatibility options:\n\
+  -o                                 when creating, same as --old-archive\n\
+                                     when extracting, same as --no-same-owner\n"),
+             stdout);
+      
+      fputs (_("\
+\n\
 The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
 The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\
 The version control may be set with --backup or VERSION_CONTROL, values are:\n\
 The version control may be set with --backup or VERSION_CONTROL, values are:\n\
 \n\
 \n\
@@ -508,7 +517,8 @@ decode_options (int argc, char **argv)
   char const *backup_suffix_string;
   char const *backup_suffix_string;
   char const *version_control_string = 0;
   char const *version_control_string = 0;
   int exclude_options = EXCLUDE_WILDCARDS;
   int exclude_options = EXCLUDE_WILDCARDS;
-
+  int o_option = 0;
+  
   /* Set some default option values.  */
   /* Set some default option values.  */
 
 
   subcommand_option = UNKNOWN_SUBCOMMAND;
   subcommand_option = UNKNOWN_SUBCOMMAND;
@@ -791,10 +801,7 @@ decode_options (int argc, char **argv)
 #endif /* not MSDOS */
 #endif /* not MSDOS */
 
 
       case 'o':
       case 'o':
-	if (archive_format == DEFAULT_FORMAT)
-	  archive_format = V7_FORMAT;
-	else if (archive_format != V7_FORMAT)
-	  USAGE_ERROR ((0, 0, _("Conflicting archive format options")));
+	o_option = 1;
 	break;
 	break;
 
 
       case 'O':
       case 'O':
@@ -1165,6 +1172,32 @@ decode_options (int argc, char **argv)
 #endif /* not DEVICE_PREFIX */
 #endif /* not DEVICE_PREFIX */
       }
       }
 
 
+  /* Special handling for 'o' option:
+
+     GNU tar used to say "output old format".
+     UNIX98 tar says don't chown files after extracting (we use
+     "--no-same-owner" for this).
+
+     The old GNU tar semantics is retained when used with --create
+     option, otherwise UNIX98 semantics is assumed */
+
+  if (o_option)
+    {
+      if (subcommand_option == CREATE_SUBCOMMAND)
+	{
+	  /* GNU Tar <= 1.13 compatibility */
+	  if (archive_format == DEFAULT_FORMAT)
+	    archive_format = V7_FORMAT;
+	  else if (archive_format != V7_FORMAT)
+	    USAGE_ERROR ((0, 0, _("Conflicting archive format options")));
+	}
+      else
+	{
+	  /* UNIX98 compatibility */
+	  same_owner_option = 1;
+	}
+    }
+
   /* Handle operands after any "--" argument.  */
   /* Handle operands after any "--" argument.  */
   for (; optind < argc; optind++)
   for (; optind < argc; optind++)
     {
     {
@@ -1396,6 +1429,9 @@ main (int argc, char **argv)
       break;
       break;
     }
     }
 
 
+  if (check_links_option)
+      check_links ();
+
   if (volno_file_option)
   if (volno_file_option)
     closeout_volume_number ();
     closeout_volume_number ();