Simplify one_top_level_dir logic

* 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.
This commit is contained in:
Paul Eggert
2026-04-07 11:47:13 -07:00
parent 90dec1cc53
commit 67c8dff696
3 changed files with 7 additions and 13 deletions

View 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

View 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;
}

View File

@@ -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);