From f90e1d0d0b0f75085f3a75a45031de80f1deca45 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 3 Jan 2023 15:27:39 -0500 Subject: [PATCH] In unarchiveToDirectory(), make zero-byte files in the archive delete existing files instead of overwrite them. --- include/system.hpp | 3 +++ src/system.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/include/system.hpp b/include/system.hpp index 3ac71d13..a5d0d5f4 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -146,6 +146,9 @@ or tar -xf archivePath --zstd -C dirPath +As a special case, zero-byte files in the archive cause the unarchiver to delete existing files instead of overwriting them. +This is useful for removing presets in .vcvplugin packages, for example. + Throws on error. */ void unarchiveToDirectory(const std::string& archivePath, const std::string& dirPath); diff --git a/src/system.cpp b/src/system.cpp index a4b3599c..2a182fc1 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -575,6 +575,12 @@ static void unarchiveToDirectory(const std::string& archivePath, const std::vect archive_entry_set_pathname(entry, entryPath.c_str()); #endif + // Delete zero-byte files + if (archive_entry_filetype(entry) == AE_IFREG && archive_entry_size(entry) == 0) { + remove(entryPath); + continue; + } + // Write entry to disk r = archive_write_header(disk, entry); if (r < ARCHIVE_OK)