Handle directory members consistently when listing and when extracting.

* src/list.c (skim_member): Recognize directory members using
the same rules as during extraction.
* tests/skipdir.at: New testcase.
* tests/testsuite.at: Add new test.
* tests/Makefile.am: Likewise.
This commit is contained in:
Sergey Poznyakoff
2025-05-12 17:20:27 +03:00
parent 827dde1605
commit b009124ffd
4 changed files with 79 additions and 3 deletions
+20 -2
View File
@@ -1414,6 +1414,23 @@ skip_member (void)
skim_member (false);
}
static bool
member_is_dir (struct tar_stat_info *info, char typeflag)
{
switch (typeflag) {
case AREGTYPE:
case REGTYPE:
case CONTTYPE:
return info->had_trailing_slash;
case DIRTYPE:
return true;
default:
return false;
}
}
/* Skip the current member in the archive.
If MUST_COPY, always copy instead of skipping. */
void
@@ -1421,14 +1438,15 @@ skim_member (bool must_copy)
{
if (!current_stat_info.skipped)
{
char save_typeflag = current_header->header.typeflag;
bool is_dir = member_is_dir (&current_stat_info,
current_header->header.typeflag);
set_next_block_after (current_header);
mv_begin_read (&current_stat_info);
if (current_stat_info.is_sparse)
sparse_skim_file (&current_stat_info, must_copy);
else if (save_typeflag != DIRTYPE)
else if (!is_dir)
skim_file (current_stat_info.stat.st_size, must_copy);
mv_end ();