From be1055f2cc8841954521bf30a6f886cf3c807a28 Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Fri, 10 Dec 2021 17:00:32 +0100 Subject: [PATCH 1/2] extract_archive: use copy_pathname instead of set_pathname. Libarchive documentation mentions that archive_entry_set_pathname expects us to keep the passed string alive, which we don't. --- src/libutil/tarfile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc index 50e691a3d..934b70162 100644 --- a/src/libutil/tarfile.cc +++ b/src/libutil/tarfile.cc @@ -93,7 +93,7 @@ static void extract_archive(TarArchive & archive, const Path & destDir) else archive.check(r); - archive_entry_set_pathname(entry, + archive_entry_copy_pathname(entry, (destDir + "/" + name).c_str()); archive.check(archive_read_extract(archive.archive, entry, flags)); From 0e0de90b35b61edcfae3030c150b9d7e42bf39fe Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Fri, 10 Dec 2021 17:03:51 +0100 Subject: [PATCH 2/2] extract_archive: fix "Hard-link target '...'" error Fixes #5741 --- src/libutil/tarfile.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libutil/tarfile.cc b/src/libutil/tarfile.cc index 934b70162..790bc943a 100644 --- a/src/libutil/tarfile.cc +++ b/src/libutil/tarfile.cc @@ -96,6 +96,13 @@ static void extract_archive(TarArchive & archive, const Path & destDir) archive_entry_copy_pathname(entry, (destDir + "/" + name).c_str()); + // Patch hardlink path + const char *original_hardlink = archive_entry_hardlink(entry); + if (original_hardlink) { + archive_entry_copy_hardlink(entry, + (destDir + "/" + original_hardlink).c_str()); + } + archive.check(archive_read_extract(archive.archive, entry, flags)); }