mirror of
https://github.com/getgrav/grav.git
synced 2026-04-12 15:47:34 +02:00
fix an error in ZipArchive that sometimes occurs
Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
@@ -64,8 +64,21 @@ class ZipArchiver extends Archiver
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if (!$zip->open($this->archive_file, ZipArchive::CREATE)) {
|
||||
throw new InvalidArgumentException('ZipArchiver:' . $this->archive_file . ' cannot be created...');
|
||||
$result = $zip->open($this->archive_file, ZipArchive::CREATE);
|
||||
if ($result !== true) {
|
||||
$error = 'unknown error';
|
||||
if ($result === ZipArchive::ER_NOENT) {
|
||||
$error = 'file does not exist';
|
||||
} elseif ($result === ZipArchive::ER_EXISTS) {
|
||||
$error = 'file already exists';
|
||||
} elseif ($result === ZipArchive::ER_OPEN) {
|
||||
$error = 'cannot open file';
|
||||
} elseif ($result === ZipArchive::ER_READ) {
|
||||
$error = 'read error';
|
||||
} elseif ($result === ZipArchive::ER_SEEK) {
|
||||
$error = 'seek error';
|
||||
}
|
||||
throw new InvalidArgumentException('ZipArchiver: ' . $this->archive_file . ' cannot be created: ' . $error);
|
||||
}
|
||||
|
||||
$files = $this->getArchiveFiles($rootPath);
|
||||
@@ -112,8 +125,21 @@ class ZipArchiver extends Archiver
|
||||
}
|
||||
|
||||
$zip = new ZipArchive();
|
||||
if (!$zip->open($this->archive_file)) {
|
||||
throw new InvalidArgumentException('ZipArchiver: ' . $this->archive_file . ' cannot be opened...');
|
||||
$result = $zip->open($this->archive_file);
|
||||
if ($result !== true) {
|
||||
$error = 'unknown error';
|
||||
if ($result === ZipArchive::ER_NOENT) {
|
||||
$error = 'file does not exist';
|
||||
} elseif ($result === ZipArchive::ER_EXISTS) {
|
||||
$error = 'file already exists';
|
||||
} elseif ($result === ZipArchive::ER_OPEN) {
|
||||
$error = 'cannot open file';
|
||||
} elseif ($result === ZipArchive::ER_READ) {
|
||||
$error = 'read error';
|
||||
} elseif ($result === ZipArchive::ER_SEEK) {
|
||||
$error = 'seek error';
|
||||
}
|
||||
throw new InvalidArgumentException('ZipArchiver: ' . $this->archive_file . ' cannot be opened: ' . $error);
|
||||
}
|
||||
|
||||
$status && $status([
|
||||
@@ -122,7 +148,12 @@ class ZipArchiver extends Archiver
|
||||
]);
|
||||
|
||||
foreach ($folders as $folder) {
|
||||
$zip->addEmptyDir($folder);
|
||||
if ($zip->addEmptyDir($folder) === false) {
|
||||
$status && $status([
|
||||
'type' => 'message',
|
||||
'message' => 'Warning: Could not add empty directory: ' . $folder
|
||||
]);
|
||||
}
|
||||
$status && $status([
|
||||
'type' => 'progress',
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user