use new (un)zip helpers
This commit is contained in:
parent
9d19150537
commit
3153c4b751
68
src/Core.php
68
src/Core.php
@ -17,7 +17,7 @@ namespace Dotclear\Plugin\pacKman;
|
|||||||
use dcCore;
|
use dcCore;
|
||||||
use dcModules;
|
use dcModules;
|
||||||
use files;
|
use files;
|
||||||
use fileUnzip;
|
use Dotclear\Helper\File\Zip\Unzip;
|
||||||
use path;
|
use path;
|
||||||
|
|
||||||
class Core
|
class Core
|
||||||
@ -65,23 +65,20 @@ class Core
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($zip_files as $zip_file) {
|
foreach ($zip_files as $zip_file) {
|
||||||
$zip_file = $root . DIRECTORY_SEPARATOR . $zip_file;
|
$zip_file = $root . DIRECTORY_SEPARATOR . $zip_file;
|
||||||
$zip = new fileUnzip($zip_file);
|
$zip = new Unzip($zip_file);
|
||||||
$zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.hg.*|\.git.*|\.DS_Store|\.directory|Thumbs\.db)(/|$)#');
|
$zip->getList(false, '#(^|/)(__MACOSX|\.svn|\.hg.*|\.git.*|\.DS_Store|\.directory|Thumbs\.db)(/|$)#');
|
||||||
|
|
||||||
$zip_root_dir = $zip->getRootDir();
|
$zip_root_dir = $zip->getRootDir();
|
||||||
$define = '';
|
|
||||||
if ($zip_root_dir != false) {
|
if ($zip_root_dir != false) {
|
||||||
$target = dirname($zip_file);
|
$target = dirname($zip_file);
|
||||||
$destination = $target . DIRECTORY_SEPARATOR . $zip_root_dir;
|
$path = $target . DIRECTORY_SEPARATOR . $zip_root_dir;
|
||||||
$define = $zip_root_dir . '/' . dcModules::MODULE_FILE_DEFINE;
|
$define = $zip_root_dir . '/' . dcModules::MODULE_FILE_DEFINE;
|
||||||
$init = $zip_root_dir . '/' . dcModules::MODULE_FILE_INIT;
|
$init = $zip_root_dir . '/' . dcModules::MODULE_FILE_INIT;
|
||||||
$has_define = $zip->hasFile($define);
|
|
||||||
} else {
|
} else {
|
||||||
$target = dirname($zip_file) . DIRECTORY_SEPARATOR . preg_replace('/\.([^.]+)$/', '', basename($zip_file));
|
$target = dirname($zip_file) . DIRECTORY_SEPARATOR . preg_replace('/\.([^.]+)$/', '', basename($zip_file));
|
||||||
$destination = $target;
|
$path = $target;
|
||||||
$define = dcModules::MODULE_FILE_DEFINE;
|
$define = dcModules::MODULE_FILE_DEFINE;
|
||||||
$init = dcModules::MODULE_FILE_INIT;
|
$init = dcModules::MODULE_FILE_INIT;
|
||||||
$has_define = $zip->hasFile($define);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($zip->isEmpty()) {
|
if ($zip->isEmpty()) {
|
||||||
@ -90,7 +87,7 @@ class Core
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$has_define) {
|
if (!$zip->hasFile($define)) {
|
||||||
$zip->close();
|
$zip->close();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -98,54 +95,39 @@ class Core
|
|||||||
|
|
||||||
foreach ($sandboxes as $type => $sandbox) {
|
foreach ($sandboxes as $type => $sandbox) {
|
||||||
try {
|
try {
|
||||||
files::makeDir($destination, true);
|
files::makeDir($path, true);
|
||||||
|
|
||||||
// can't load twice _init.php file !
|
// can't load twice _init.php file !
|
||||||
$unlink = false;
|
$unlink = false;
|
||||||
if ($zip->hasFile($init)
|
if ($zip->hasFile($init)) {
|
||||||
// && !dcCore::app()->plugins->getDefine(basename($destination))->isDefined()
|
|
||||||
// && !dcCore::app()->themes->getDefine(basename($destination))->isDefined()
|
|
||||||
) {
|
|
||||||
$unlink = true;
|
$unlink = true;
|
||||||
$zip->unzip($init, $destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_INIT);
|
$zip->unzip($init, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->unzip($define, $destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_DEFINE);
|
$zip->unzip($define, $path);
|
||||||
|
|
||||||
$sandbox->resetModulesList();
|
$sandbox->resetModulesList();
|
||||||
$sandbox->requireDefine($destination, basename($destination));
|
$sandbox->requireDefine($path, basename($path));
|
||||||
|
|
||||||
if ($unlink) {
|
if ($unlink) {
|
||||||
unlink($destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_INIT);
|
unlink($target . DIRECTORY_SEPARATOR . $init);
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink($destination . DIRECTORY_SEPARATOR . dcModules::MODULE_FILE_DEFINE);
|
unlink($target . DIRECTORY_SEPARATOR . $define);
|
||||||
|
|
||||||
$new_errors = $sandbox->getErrors();
|
if (!$sandbox->getErrors()) {
|
||||||
if (!empty($new_errors)) {
|
$module = $sandbox->getDefine(basename($path));
|
||||||
$new_errors = implode(" \n", $new_errors);
|
if ($module->isDefined() && $module->get('type') == $type) {
|
||||||
|
$res[$i] = $module->dump();
|
||||||
throw new Exception($new_errors);
|
$res[$i]['root'] = $zip_file;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$module = $sandbox->getDefine(basename($destination));
|
|
||||||
if (!$module->isDefined() || $module->get('type') != $type) {
|
|
||||||
throw new Exception('bad module type');
|
|
||||||
}
|
|
||||||
|
|
||||||
$res[$i] = $module->dump();
|
|
||||||
$res[$i]['root'] = $zip_file;
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
$zip->close();
|
|
||||||
files::deltree($destination);
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$zip->close();
|
|
||||||
files::deltree($destination);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
files::deltree($path);
|
||||||
}
|
}
|
||||||
|
$zip->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
@ -169,15 +151,14 @@ class Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
@set_time_limit(300);
|
@set_time_limit(300);
|
||||||
$fp = fopen($dest, 'wb');
|
|
||||||
|
|
||||||
if ($nocomment) {
|
if ($nocomment) {
|
||||||
Filezip::$remove_comment = true;
|
Zip::$remove_comment = true;
|
||||||
}
|
}
|
||||||
if ($fixnewline) {
|
if ($fixnewline) {
|
||||||
Filezip::$fix_newline = true;
|
Zip::$fix_newline = true;
|
||||||
}
|
}
|
||||||
$zip = new Filezip($fp);
|
$zip = new Zip($dest);
|
||||||
|
|
||||||
foreach ($exclude as $e) {
|
foreach ($exclude as $e) {
|
||||||
$zip->addExclusion($e);
|
$zip->addExclusion($e);
|
||||||
@ -188,7 +169,6 @@ class Core
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$zip->write();
|
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unset($zip);
|
unset($zip);
|
||||||
}
|
}
|
||||||
|
15
src/Zip.php
15
src/Zip.php
@ -14,9 +14,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\pacKman;
|
namespace Dotclear\Plugin\pacKman;
|
||||||
|
|
||||||
//use fileZip;
|
class Zip extends \Dotclear\Helper\File\Zip\Zip
|
||||||
|
|
||||||
class Filezip extends \fileZip
|
|
||||||
{
|
{
|
||||||
/** @var boolean Remove comments from files content */
|
/** @var boolean Remove comments from files content */
|
||||||
public static $remove_comment = false;
|
public static $remove_comment = false;
|
||||||
@ -27,14 +25,13 @@ class Filezip extends \fileZip
|
|||||||
/**
|
/**
|
||||||
* Replace clearbricks fileZip::writeFile
|
* Replace clearbricks fileZip::writeFile
|
||||||
*
|
*
|
||||||
* @param string $name Name
|
* @param string $name The name
|
||||||
* @param string $file File
|
* @param string $file The file
|
||||||
* @param int $size Size
|
* @param int|null $mtime The mtime
|
||||||
* @param int $mtime Mtime
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function writeFile($name, $file, $size, $mtime)
|
protected function writeFile(string $name, string $file, ?int $mtime)
|
||||||
{
|
{
|
||||||
if (!isset($this->entries[$name])) {
|
if (!isset($this->entries[$name])) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user