Skip to content

Commit

Permalink
Fix handling of symlinks extracted from zip files
Browse files Browse the repository at this point in the history
Setting unix attributes was breaking the detection of symlinks by
Archive::Zip, so it was just writing out a file with the name of the
linked file in it.

Fix it by instead removing an existing file if it exists and not setting
permissions for symlinks. This allows Arhive::Zip to always create a
proper symlink. While at it, change the permissions for files to we
writable by the owner, so as to avoid any other permissions issues when
re-indexing an archive, which needs to replace existing files.

Finallky, don't abandon unzipping a file on error, but just move on to
the next file.
  • Loading branch information
theory committed Mar 14, 2024
1 parent 3658cbd commit 7f77cd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for Perl extension PGXN::API

0.20.2
- Fixed symlinks extracted from Zip files and permission errors when
re-indexing distributions.

0.20.1 2024-02-15T22:18:14Z
- Fixed a bug where a testing extension's version and abstract was not
Expand Down
16 changes: 11 additions & 5 deletions lib/PGXN/API/Sync.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,20 @@ sub unzip {
make_path $dist_dir unless -e $dist_dir && -d _;

foreach my $member ($zip->members) {
# Make sure the file is readable by everyone
$member->unixFileAttributes( $member->isDirectory ? 0755 : 0444 );
my $fn = catfile $dist_dir, split m{/} => $member->fileName;
say " $fn\n" if $self->verbose > 2;

if ($member->isSymbolicLink) {
# Delete exsting so Archive::Zip won't fail to create it.
warn "Cannot unlink $fn: $!\n" if -e $fn && !unlink $fn;
} else {
# Make sure the member is readable by everyone.
$member->unixFileAttributes( $member->isDirectory ? 0755 : 0644 );
}

if ($member->extractToFileNamed($fn) != AZ_OK) {
warn "Error extracting $zip_path\n";
## XXX clean up the mess here.
return;
warn "Error extracting $fn from $zip_path\n";
next;
}
}

Expand Down

0 comments on commit 7f77cd7

Please sign in to comment.