Skip to content

Commit

Permalink
Handle entry/file permissions in 7z archives
Browse files Browse the repository at this point in the history
  • Loading branch information
sirjuddington committed Apr 13, 2024
1 parent cd64f61 commit 5d562b1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Archive/Formats/7zArchiveHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
using namespace slade;


// -----------------------------------------------------------------------------
//
// Variables
//
// -----------------------------------------------------------------------------
namespace
{
constexpr unsigned short default_perm = 0644;
constexpr string perm_key = "7zPermissions";
} // namespace


// -----------------------------------------------------------------------------
//
// Functions
Expand Down Expand Up @@ -142,6 +154,7 @@ bool read7z(ArchiveFormatHandler& handler, Archive& archive, struct archive* arc

// Set entry info
new_entry->exProp("ZipIndex") = index;
new_entry->exProp(perm_key) = static_cast<int>(archive_entry_perm(entry_7z));
}
else
{
Expand Down Expand Up @@ -283,9 +296,14 @@ bool Zip7ArchiveHandler::write(Archive& archive, string_view filename)
auto path = entry->path().append(misc::lumpNameToFileName(entry->name()));
strutil::removePrefixIP(path, '/');

auto permissions = default_perm;
if (entry->exProps().contains(perm_key))
permissions = static_cast<unsigned short>(entry->exProp<int>(perm_key));

// Setup entry info
archive_entry_set_pathname_utf8(entry_7z, path.c_str());
archive_entry_set_size(entry_7z, entry->size());
archive_entry_set_perm(entry_7z, permissions);
if (entry->isFolderType())
archive_entry_set_filetype(entry_7z, AE_IFDIR);
else
Expand Down

0 comments on commit 5d562b1

Please sign in to comment.