From c809e2c6e09e4a8a40a84a8f75f3df4a23105b26 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 27 Apr 2023 21:51:51 +0200 Subject: [PATCH] rollback dotclear Un|Zip class --- src/Config.php | 5 ----- src/Core.php | 10 ++++++--- src/Utils.php | 58 -------------------------------------------------- src/Zip.php | 3 ++- 4 files changed, 9 insertions(+), 67 deletions(-) diff --git a/src/Config.php b/src/Config.php index 99fb0d3..5860fcd 100644 --- a/src/Config.php +++ b/src/Config.php @@ -161,11 +161,6 @@ class Config extends dcNsProcess (new Label(__('Fix newline style from files content'), Label::OUTSIDE_LABEL_AFTER))->for('pack_fixnewline')->class('classic'), ]), ]), - (new Fieldset())->class('fieldset')->legend((new Legend(__('Capability'))))->fields([ - (new Text('p', $img_on . sprintf(__('Use "%s" class to zip modules.'), Utils::getZipCapability()))), - (new Text('p', $img_on . sprintf(__('Use "%s" class to unzip modules.'), Utils::getUnzipCapability()))), - (new Text('p', $check_conf)), - ]), ])->render(); } } diff --git a/src/Core.php b/src/Core.php index f7f1400..1fcd380 100644 --- a/src/Core.php +++ b/src/Core.php @@ -102,10 +102,10 @@ class Core $unlink = false; if ($zip->hasFile($init)) { $unlink = true; - $zip->unzip($init, $path); + $zip->unzip($init, $target . DIRECTORY_SEPARATOR . $init); } - $zip->unzip($define, $path); + $zip->unzip($define, $target . DIRECTORY_SEPARATOR . $define); $sandbox->resetModulesList(); $sandbox->requireDefine($path, basename($path)); @@ -125,6 +125,7 @@ class Core } } } catch (Exception $e) { + throw $e; } Files::deltree($path); } @@ -173,7 +174,9 @@ class Core if ($fixnewline) { Zip::$fix_newline = true; } - $zip = new Zip($path); + + $fp = fopen($path, 'wb'); + $zip = new Zip($fp); foreach ($exclude as $e) { $zip->addExclusion($e); @@ -184,6 +187,7 @@ class Core true ); + $zip->write(); $zip->close(); unset($zip); } diff --git a/src/Utils.php b/src/Utils.php index f04727a..05c3338 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -81,64 +81,6 @@ class Utils return !(empty($path) || empty($file) || !is_writable(dirname($path . DIRECTORY_SEPARATOR . $file))); } - public static function getUnzipCapability(): string - { - switch (Unzip::USE_DEFAULT) { - case Unzip::USE_PHARDATA: - if (class_exists('PharData')) { - return 'PharData'; - } - if (class_exists('ZipArchive')) { - return 'ZipArchive'; - } - - break; - case Unzip::USE_ZIPARCHIVE: - if (class_exists('ZipArchive')) { - return 'ZipArchive'; - } - if (class_exists('PharData')) { - return 'PharData'; - } - - break; - case Unzip::USE_LEGACY: - - break; - } - - return 'Legacy'; - } - - public static function getZipCapability(): string - { - switch (Zip::USE_DEFAULT) { - case Zip::USE_PHARDATA: - if (class_exists('PharData')) { - return 'PharData'; - } - if (class_exists('ZipArchive')) { - return 'ZipArchive'; - } - - break; - case Zip::USE_ZIPARCHIVE: - if (class_exists('ZipArchive')) { - return 'ZipArchive'; - } - if (class_exists('PharData')) { - return 'PharData'; - } - - break; - case Unzip::USE_LEGACY: - - break; - } - - return 'Legacy'; - } - public static function getRepositoryDir(?string $dir): string { if (empty($dir)) { diff --git a/src/Zip.php b/src/Zip.php index 595992f..42ed6f8 100644 --- a/src/Zip.php +++ b/src/Zip.php @@ -27,11 +27,12 @@ class Zip extends \Dotclear\Helper\File\Zip\Zip * * @param string $name The name * @param string $file The file + * @param string $size The size * @param int|null $mtime The mtime * * @return void */ - protected function writeFile(string $name, string $file, ?int $mtime) + protected function writeFile($name, $file, $size, $mtime) { if (!isset($this->entries[$name])) { return;