]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Simplify one_top_level_dir logic
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 7 Apr 2026 18:47:13 +0000 (11:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 8 Apr 2026 16:07:12 +0000 (09:07 -0700)
* src/tar.c (one_top_level_option): Remove.  All uses removed.
All external uses changed to equivalent of !!one_top_level_dir.
(decode_options): Set one_top_level_dir to be consistent with
the old one_top_level_option.

src/common.h
src/list.c
src/tar.c

index 032c0a1fa4cc8f0e465e04649463297a0c0cdaa7..62dd5aefe602f22454ee3010bcf2767ecffc7c6f 100644 (file)
@@ -243,7 +243,6 @@ extern bool numeric_owner_option;
 extern bool one_file_system_option;
 
 /* Create a top-level directory for extracting based on the archive name.  */
-extern bool one_top_level_option;
 extern char *one_top_level_dir;
 
 /* Specified value to be put into tar file in place of stat () results, or
index 14050cfb2ea683e5e7f10467fc49c3353b2b20ea..5ab6de420904166d9f674e07fb3a72fb83083cde 100644 (file)
@@ -170,7 +170,7 @@ transform_stat_info (char typeflag, struct tar_stat_info *stat_info)
       break;
     }
 
-  if (one_top_level_option)
+  if (one_top_level_dir)
     enforce_one_top_level (&stat_info->file_name);
   return true;
 }
index 1df9460c6c637794ecd533e30cbb3ad9a66163df..57609d96768f98b7a0d628f1f98883c1321f5fc7 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -73,7 +73,6 @@ char *set_mtime_format;
 int recursion_option;
 bool numeric_owner_option;
 bool one_file_system_option;
-bool one_top_level_option;
 char *one_top_level_dir;
 char const *owner_name_option;
 uid_t owner_option;
@@ -1630,7 +1629,6 @@ parse_opt (int key, char *arg, struct argp_state *state)
 
     case ONE_TOP_LEVEL_OPTION:
       optloc_save (OC_ONE_TOP_LEVEL, args->loc);
-      one_top_level_option = true;
       one_top_level_dir = arg;
       break;
 
@@ -2656,10 +2654,8 @@ decode_options (int argc, char **argv)
        same_order_option = false;
     }
 
-  if (one_top_level_option)
+  if (optloc_lookup (OC_ONE_TOP_LEVEL))
     {
-      char *base;
-
       if (absolute_names_option)
        {
          struct option_locus *one_top_level_loc =
@@ -2669,17 +2665,16 @@ decode_options (int argc, char **argv)
 
          if (optloc_eq (one_top_level_loc, absolute_names_loc))
            option_conflict_error ("--one-top-level", "--absolute-names");
-         else if (one_top_level_loc->source == OPTS_COMMAND_LINE)
+         if (one_top_level_loc->source == OPTS_COMMAND_LINE)
            absolute_names_option = false;
          else
-           one_top_level_option = false;
+           one_top_level_dir = NULL;
        }
 
-      if (!one_top_level_dir && one_top_level_option)
+      if (!absolute_names_option && !one_top_level_dir)
        {
-         /* If the user wants to guarantee that everything is under one
-            directory, determine its name now and let it be created later.  */
-         base = base_name (archive_name_array[0]);
+         /* Determine name now; the directory is created later if needed.  */
+         char *base = base_name (archive_name_array[0]);
          one_top_level_dir = strip_compression_suffix (base);
          free (base);