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:
Sergey Poznyakoff
2010-03-11 17:41:23 +02:00
parent 8d3cc6c3cf
commit 0ba8bdf5f3
10 changed files with 329 additions and 47 deletions
+1 -3
View File
@@ -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
View File
@@ -1412,22 +1412,23 @@ test_archive_label ()
if (read_header (&current_header, &current_stat_info, read_header_auto)
== HEADER_SUCCESS)
{
char *s = NULL;
decode_header (current_header,
&current_stat_info, &current_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
View File
@@ -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. */