This bug was introduced by the recent lseek-related changes.
* src/delete.c (delete_archive_members):
* src/update.c (update_archive):
Copy the member if acting as a filter, rather than lseeking over
it, which is possible if stdin is a regular file.
* src/list.c (skim_file, skim_member):
* src/sparse.c (sparse_skim_file):
New functions, for copying when a filter.
* src/list.c (skip_file): Remove; replaced with skim_file.
All callers changed.
(skip_member): Reimplement in terms of skim_member.
* src/sparse.c (sparse_skip_file):
Remove; replaced with sparse_skim_file. All callers changed.
* src/update.c (acting_as_filter): New static var.
(update_archive): Set it; this is like delete.c.
* tests/delete01.at (deleting a member after a big one):
* tests/delete02.at (deleting a member from stdin archive):
Also test filter case.
struct tar_stat_info *info,
enum read_header_mode m);
enum read_header tar_checksum (union block *header, bool silent);
-void skip_file (off_t size);
+void skim_file (off_t size, bool must_copy);
void skip_member (void);
+void skim_member (bool must_copy);
/* Module misc.c. */
enum dump_status sparse_dump_file (int, struct tar_stat_info *st);
enum dump_status sparse_extract_file (int fd, struct tar_stat_info *st,
off_t *size);
-enum dump_status sparse_skip_file (struct tar_stat_info *st);
+enum dump_status sparse_skim_file (struct tar_stat_info *st, bool must_copy);
bool sparse_diff_file (int, struct tar_stat_info *st);
/* Module utf8.c */
case HEADER_SUCCESS:
if ((name = name_scan (current_stat_info.file_name)) == NULL)
{
- skip_member ();
+ skim_member (acting_as_filter);
break;
}
name->found_count++;
if (!ISFOUND (name))
{
- skip_member ();
+ skim_member (acting_as_filter);
break;
}
FALLTHROUGH;
}
}
- skip_file (size);
+ skim_file (size, false);
mv_end ();
size_t next_long_name_blocks = 0;
size_t next_long_link_blocks = 0;
enum read_header status = HEADER_SUCCESS;
-
+
while (1)
{
header = find_next_block ();
}
}
-/* Skip over SIZE bytes of data in blocks in the archive. */
+/* Skip over SIZE bytes of data in blocks in the archive.
+ This may involve copying the data.
+ If MUST_COPY, always copy instead of skipping. */
void
-skip_file (off_t size)
+skim_file (off_t size, bool must_copy)
{
union block *x;
/* FIXME: Make sure mv_begin_read is always called before it */
- if (seekable_archive)
+ if (seekable_archive && !must_copy)
{
off_t nblk = seek_archive (size);
if (nblk >= 0)
NOTE: Current header must be decoded before calling this function. */
void
skip_member (void)
+{
+ skim_member (false);
+}
+
+/* Skip the current member in the archive.
+ If MUST_COPY, always copy instead of skipping. */
+void
+skim_member (bool must_copy)
{
if (!current_stat_info.skipped)
{
mv_begin_read (¤t_stat_info);
if (current_stat_info.is_sparse)
- sparse_skip_file (¤t_stat_info);
+ sparse_skim_file (¤t_stat_info, must_copy);
else if (save_typeflag != DIRTYPE)
- skip_file (current_stat_info.stat.st_size);
+ skim_file (current_stat_info.stat.st_size, must_copy);
mv_end ();
}
}
enum dump_status
-sparse_skip_file (struct tar_stat_info *st)
+sparse_skim_file (struct tar_stat_info *st, bool must_copy)
{
bool rc = true;
struct tar_sparse_file file;
file.fd = -1;
rc = tar_sparse_decode_header (&file);
- skip_file (file.stat_info->archive_file_size - file.dumped_size);
+ skim_file (file.stat_info->archive_file_size - file.dumped_size, must_copy);
return (tar_sparse_done (&file) && rc) ? dump_status_ok : dump_status_short;
}
}
if (!rc)
- skip_file (file.stat_info->archive_file_size - file.dumped_size);
+ skim_file (file.stat_info->archive_file_size - file.dumped_size, false);
mv_end ();
tar_sparse_done (&file);
first part of the record. */
char *output_start;
+static bool acting_as_filter;
+
/* Catenate file FILE_NAME to the archive without creating a header for it.
It had better be a tar file or the archive is screwed. */
static void
name_gather ();
open_archive (ACCESS_UPDATE);
+ acting_as_filter = strcmp (archive_name_array[0], "-") == 0;
xheader_forbid_global ();
while (!found_end)
}
}
- skip_member ();
+ skim_member (acting_as_filter);
break;
}
genfile -l 50000 --file file1
genfile -l 1024 --file file2
tar cf archive file1 file2
+tar -f - --delete file2 <archive >archout
+tar tf archout
tar f archive --delete file2
-tar tf archive],
+cmp archive archout],
[0],
[file1
])
tar tf archive
cat archive | tar f - --delete 2 > archive2
echo separator
-tar tf archive2],
+tar tf archive2
+tar f - --delete 2 < archive > archive3
+cmp archive2 archive3],
[0],
[1
2