aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Archive
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Archive')
-rw-r--r--lib/private/Archive/Archive.php39
-rw-r--r--lib/private/Archive/TAR.php73
-rw-r--r--lib/private/Archive/ZIP.php43
3 files changed, 38 insertions, 117 deletions
diff --git a/lib/private/Archive/Archive.php b/lib/private/Archive/Archive.php
index cef306230fd..874087fb167 100644
--- a/lib/private/Archive/Archive.php
+++ b/lib/private/Archive/Archive.php
@@ -1,31 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Archive;
@@ -50,9 +28,8 @@ abstract class Archive {
/**
* get the uncompressed size of a file in the archive
- * @return int|false
*/
- abstract public function filesize(string $path);
+ abstract public function filesize(string $path): false|int|float;
/**
* get the last modified time of a file in the archive
@@ -115,10 +92,10 @@ abstract class Archive {
if ($file === '.' || $file === '..') {
continue;
}
- if (is_dir($source.'/'.$file)) {
- $this->addRecursive($path.'/'.$file, $source.'/'.$file);
+ if (is_dir($source . '/' . $file)) {
+ $this->addRecursive($path . '/' . $file, $source . '/' . $file);
} else {
- $this->addFile($path.'/'.$file, $source.'/'.$file);
+ $this->addFile($path . '/' . $file, $source . '/' . $file);
}
}
}
diff --git a/lib/private/Archive/TAR.php b/lib/private/Archive/TAR.php
index 79c09cbe9e2..e08720a75a5 100644
--- a/lib/private/Archive/TAR.php
+++ b/lib/private/Archive/TAR.php
@@ -1,34 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Remco Brenninkmeijer <requist1@starmail.nl>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Archive;
@@ -48,15 +23,9 @@ class TAR extends Archive {
*/
private $cachedHeaders = false;
- /**
- * @var \Archive_Tar
- */
- private $tar = null;
+ private \Archive_Tar $tar;
- /**
- * @var string
- */
- private $path;
+ private string $path;
public function __construct(string $source) {
$types = [null, 'gz', 'bz2'];
@@ -137,7 +106,7 @@ class TAR extends Archive {
$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
$this->tar->extract($tmp);
rename($tmp . $source, $tmp . $dest);
- $this->tar = null;
+ $this->tar->_close();
unlink($this->path);
$types = [null, 'gz', 'bz'];
$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
@@ -165,10 +134,8 @@ class TAR extends Archive {
/**
* get the uncompressed size of a file in the archive
- *
- * @return int|false
*/
- public function filesize(string $path) {
+ public function filesize(string $path): false|int|float {
$stat = $this->getHeader($path);
return $stat['size'] ?? false;
}
@@ -199,7 +166,7 @@ class TAR extends Archive {
if ($pos = strpos($result, '/')) {
$result = substr($result, 0, $pos + 1);
}
- if (array_search($result, $folderContent) === false) {
+ if (!in_array($result, $folderContent)) {
$folderContent[] = $result;
}
}
@@ -211,11 +178,16 @@ class TAR extends Archive {
* get all files in the archive
*/
public function getFiles(): array {
- if ($this->fileList) {
+ if ($this->fileList !== false) {
return $this->fileList;
}
- if (!$this->cachedHeaders) {
- $this->cachedHeaders = $this->tar->listContent();
+ if ($this->cachedHeaders === false) {
+ $headers = $this->tar->listContent();
+ if (is_array($headers)) {
+ $this->cachedHeaders = $headers;
+ } else {
+ return [];
+ }
}
$files = [];
foreach ($this->cachedHeaders as $header) {
@@ -232,6 +204,7 @@ class TAR extends Archive {
*/
public function getFile(string $path) {
$string = $this->tar->extractInString($path);
+ /** @var ?string $string */
if (is_string($string)) {
return $string;
} else {
@@ -271,7 +244,7 @@ class TAR extends Archive {
*/
public function fileExists(string $path): bool {
$files = $this->getFiles();
- if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
+ if ((in_array($path, $files)) or (in_array($path . '/', $files))) {
return true;
} else {
$folderPath = rtrim($path, '/') . '/';
@@ -302,7 +275,6 @@ class TAR extends Archive {
$tmp = \OC::$server->getTempManager()->getTemporaryFolder();
$this->tar->extract($tmp);
\OCP\Files::rmdirr($tmp . $path);
- $this->tar = null;
unlink($this->path);
$this->reopen();
$this->tar->createModify([$tmp], '', $tmp);
@@ -349,10 +321,7 @@ class TAR extends Archive {
* reopen the archive to ensure everything is written
*/
private function reopen(): void {
- if ($this->tar) {
- $this->tar->_close();
- $this->tar = null;
- }
+ $this->tar->_close();
$types = [null, 'gz', 'bz'];
$this->tar = new \Archive_Tar($this->path, $types[self::getTarType($this->path)]);
}
@@ -361,7 +330,7 @@ class TAR extends Archive {
* Get error object from archive_tar.
*/
public function getError(): ?\PEAR_Error {
- if ($this->tar instanceof \Archive_Tar && $this->tar->error_object instanceof \PEAR_Error) {
+ if ($this->tar->error_object instanceof \PEAR_Error) {
return $this->tar->error_object;
}
return null;
diff --git a/lib/private/Archive/ZIP.php b/lib/private/Archive/ZIP.php
index 743d313f951..61fd25d071d 100644
--- a/lib/private/Archive/ZIP.php
+++ b/lib/private/Archive/ZIP.php
@@ -1,33 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Christopher Schäpers <kondou@ts.unde.re>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Stefan Weil <sw@weilnetz.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Archive;
@@ -50,7 +26,7 @@ class ZIP extends Archive {
$this->zip = new \ZipArchive();
if ($this->zip->open($source, \ZipArchive::CREATE)) {
} else {
- \OC::$server->get(LoggerInterface::class)->warning('Error while opening archive '.$source, ['app' => 'files_archive']);
+ \OC::$server->get(LoggerInterface::class)->warning('Error while opening archive ' . $source, ['app' => 'files_archive']);
}
}
@@ -91,9 +67,8 @@ class ZIP extends Archive {
/**
* get the uncompressed size of a file in the archive
- * @return int|false
*/
- public function filesize(string $path) {
+ public function filesize(string $path): false|int|float {
$stat = $this->zip->statName($path);
return $stat['size'] ?? false;
}
@@ -194,15 +169,15 @@ class ZIP extends Archive {
* check if a file or folder exists in the archive
*/
public function fileExists(string $path): bool {
- return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path.'/') !== false);
+ return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path . '/') !== false);
}
/**
* remove a file or folder from the archive
*/
public function remove(string $path): bool {
- if ($this->fileExists($path.'/')) {
- return $this->zip->deleteName($path.'/');
+ if ($this->fileExists($path . '/')) {
+ return $this->zip->deleteName($path . '/');
} else {
return $this->zip->deleteName($path);
}