mirror of
https://git.savannah.gnu.org/git/tar.git
synced 2026-09-18 22:24:15 +00:00
Fix --test-label' and --label -r' behavior.
* doc/tar.texi (Including a Label in the Archive): Revise the section. * NEWS: Update * src/buffer.c (open_archive): Check volume label on ACCESS_UPDATE as well. * src/list.c (test_archive_label): Rewrite to match the documentation. * src/names.c (regex_usage_warning): Return int. (names_notfound): Rewrite the conditional. (label_notfound): New function. * tests/label03.at: New testcase. * tests/label04.at: New testcase. * tests/label05.at: New testcase. * tests/Makefile.am: Add new testcases. * tests/testsuite.at: Likewise.
This commit is contained in:
+1
-3
@@ -1841,6 +1841,7 @@ open_archive (enum access_mode wanted_access)
|
||||
switch (wanted_access)
|
||||
{
|
||||
case ACCESS_READ:
|
||||
case ACCESS_UPDATE:
|
||||
if (volume_label_option)
|
||||
match_volume_label ();
|
||||
break;
|
||||
@@ -1850,9 +1851,6 @@ open_archive (enum access_mode wanted_access)
|
||||
if (volume_label_option)
|
||||
write_volume_label ();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
set_volume_start_time ();
|
||||
}
|
||||
|
||||
+13
-12
@@ -1412,22 +1412,23 @@ test_archive_label ()
|
||||
if (read_header (¤t_header, ¤t_stat_info, read_header_auto)
|
||||
== HEADER_SUCCESS)
|
||||
{
|
||||
char *s = NULL;
|
||||
|
||||
decode_header (current_header,
|
||||
¤t_stat_info, ¤t_format, 0);
|
||||
if (current_header->header.typeflag == GNUTYPE_VOLHDR)
|
||||
assign_string (&volume_label, current_header->header.name);
|
||||
|
||||
if (volume_label
|
||||
&& (name_match (volume_label)
|
||||
|| (multi_volume_option
|
||||
&& (s = drop_volume_label_suffix (volume_label))
|
||||
&& name_match (s))))
|
||||
if (verbose_option)
|
||||
print_volume_label ();
|
||||
free (s);
|
||||
|
||||
if (volume_label)
|
||||
{
|
||||
if (verbose_option)
|
||||
print_volume_label ();
|
||||
if (!name_match (volume_label) && multi_volume_option)
|
||||
{
|
||||
char *s = drop_volume_label_suffix (volume_label);
|
||||
name_match (s);
|
||||
free (s);
|
||||
}
|
||||
}
|
||||
}
|
||||
close_archive ();
|
||||
names_notfound ();
|
||||
label_notfound ();
|
||||
}
|
||||
|
||||
+43
-7
@@ -589,7 +589,7 @@ all_names_found (struct tar_stat_info *p)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
regex_usage_warning (const char *name)
|
||||
{
|
||||
static int warned_once = 0;
|
||||
@@ -603,6 +603,7 @@ regex_usage_warning (const char *name)
|
||||
_("Use --wildcards to enable pattern matching,"
|
||||
" or --no-wildcards to suppress this warning")));
|
||||
}
|
||||
return warned_once;
|
||||
}
|
||||
|
||||
/* Print the names of things in the namelist that were not matched. */
|
||||
@@ -615,12 +616,11 @@ names_notfound (void)
|
||||
if (!WASFOUND (cursor) && cursor->name[0])
|
||||
{
|
||||
regex_usage_warning (cursor->name);
|
||||
if (cursor->found_count == 0)
|
||||
ERROR ((0, 0, _("%s: Not found in archive"),
|
||||
quotearg_colon (cursor->name)));
|
||||
else
|
||||
ERROR ((0, 0, _("%s: Required occurrence not found in archive"),
|
||||
quotearg_colon (cursor->name)));
|
||||
ERROR ((0, 0,
|
||||
(cursor->found_count == 0) ?
|
||||
_("%s: Not found in archive") :
|
||||
_("%s: Required occurrence not found in archive"),
|
||||
quotearg_colon (cursor->name)));
|
||||
}
|
||||
|
||||
/* Don't bother freeing the name list; we're about to exit. */
|
||||
@@ -639,6 +639,42 @@ names_notfound (void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
label_notfound (void)
|
||||
{
|
||||
struct name const *cursor;
|
||||
|
||||
if (!namelist)
|
||||
return;
|
||||
|
||||
for (cursor = namelist; cursor; cursor = cursor->next)
|
||||
if (WASFOUND (cursor))
|
||||
return;
|
||||
|
||||
if (verbose_option)
|
||||
error (0, 0, _("Archive label mismatch"));
|
||||
set_exit_status (TAREXIT_DIFFERS);
|
||||
|
||||
for (cursor = namelist; cursor; cursor = cursor->next)
|
||||
{
|
||||
if (regex_usage_warning (cursor->name))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Don't bother freeing the name list; we're about to exit. */
|
||||
namelist = NULL;
|
||||
nametail = NULL;
|
||||
|
||||
if (same_order_option)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
while ((name = name_next (1)) != NULL
|
||||
&& regex_usage_warning (name) == 0)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sorting name lists. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user