Skip to content

Commit

Permalink
Fix(ZipTask): check if setMtimeIndex is available
Browse files Browse the repository at this point in the history
ZipArchive::setMtimeIndex (PHP >= 8.0.0, PECL zip >= 1.16.0)
  • Loading branch information
leagris committed Apr 29, 2024
1 parent ea5b6e5 commit 964686e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Phing/Task/Ext/Archive/ZipTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ private static function fixDirAttributes($zip, $f, $pathInZip)
{
$indexInZip = $zip->locateName('/' === mb_substr($pathInZip, -1) ? $pathInZip : $pathInZip . '/');
if (false !== $indexInZip) {
$zip->setMtimeIndex($indexInZip, $f->lastModified());
if (method_exists($zip, 'setMtimeIndex')) { // PHP >= 8.0.0, PECL zip >= 1.16.0
$zip->setMtimeIndex($indexInZip, $f->lastModified());
}
$filePerms = fileperms($f->getPath());
if (false !== $filePerms) { // filePerms supported
$zip->setExternalAttributesIndex($indexInZip, \ZipArchive::OPSYS_DEFAULT, $filePerms << 16);
Expand All @@ -103,7 +105,7 @@ private static function fixDirAttributes($zip, $f, $pathInZip)
private static function clearExternalAttributes($zip)
{
for ($i = 0, $count = $zip->count(); $i < $count; ++$i) {
$zip->setExternalAttributesIndex($i, \ZipArchive::OPSYS_DOS, null);
$zip->setExternalAttributesIndex($i, \ZipArchive::OPSYS_DOS, 0);
}
}

Expand Down

0 comments on commit 964686e

Please sign in to comment.