Draft patch for openat2 changes vs --one-top-level

The patch leverages the existing -C code. In order to do that, every
entry in the wd[] table gets another companion entry in the table that
represents the --one-top-level directory. There is one additional field
in each entry that allows skipping the companion entries if they are not
desired.

The actual directory is created lazily by chdir_do() if needed, as you
requested, to avoid empty "a/foo" after --one-top-level=foo -C a -C b.

The patch "by the way" fixes also extraction of hardlinks with
--one-top-level which currently is broken in the typical case (the
transform is not applied to the target, so the hardlink is wrong).

The patch does not yet handle the --show-transformed case with
--one-top-level that you discussed in another subthread. As a result, two
tests now fail (onetop02.at and onetop04.at). I suppose that this would
be quite easy to fix.

Another issue that I am aware of is that I am not sure whether to call
repair_delayed_set_stat and/or delay_set_stat on the newly created
directories like extract_dir() does (the whole delay_set code is abit
mysterious to me).

Use of --create together with --one-top-level should probably be
forbidden, as unlink.c uses wd[] in a way that will likely break in the
presence of companion entries (the chdir_do call in
flush_deferred_unlinks).

Show the one-top-level arg as a transformation
This commit is contained in:
Pavel Cahyna
2026-07-29 23:12:46 -07:00
committed by Paul Eggert
parent e407e6e7dd
commit 1b91f5f66f
8 changed files with 267 additions and 54 deletions
+4 -4
View File
@@ -92,7 +92,7 @@ flush_deferred_unlinks (bool force)
if (force
|| p->records_written < records_written)
{
chdir_do (p->dir_idx);
chdir_do (p->dir_idx, false);
if (p->is_dir)
{
const char *fname;
@@ -163,11 +163,11 @@ flush_deferred_unlinks (bool force)
struct deferred_unlink *next = p->next;
const char *fname;
chdir_do (p->dir_idx);
chdir_do (p->dir_idx, false);
if (p->dir_idx && is_cwd (p))
{
fname = tar_dirname ();
chdir_do (p->dir_idx - 1);
chdir_do (p->dir_idx - 1, false);
}
else
fname = p->file_name;
@@ -184,7 +184,7 @@ flush_deferred_unlinks (bool force)
dunlink_head = dunlink_tail = NULL;
}
chdir_do (saved_chdir);
chdir_do (saved_chdir, false);
}
void