diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-04-29 15:21:52 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-04-30 09:24:00 +0200 |
commit | 2333657fb6727860f512dcd55e92bdd5e856e2e6 (patch) | |
tree | ae192f70ade33274c1c67038a609f59f2c76ebd2 /lib/private/Archive/TAR.php | |
parent | ece358825237e7a34b27e54805a0b734962f328b (diff) | |
download | nextcloud-server-2333657fb6727860f512dcd55e92bdd5e856e2e6.tar.gz nextcloud-server-2333657fb6727860f512dcd55e92bdd5e856e2e6.zip |
fix: Improve typing in Archive/TAR.php
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib/private/Archive/TAR.php')
-rw-r--r-- | lib/private/Archive/TAR.php | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/private/Archive/TAR.php b/lib/private/Archive/TAR.php index a6140e44eb6..ef300b0f3b0 100644 --- a/lib/private/Archive/TAR.php +++ b/lib/private/Archive/TAR.php @@ -48,15 +48,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 +131,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)]); @@ -209,11 +203,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) { @@ -230,6 +229,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 { @@ -300,7 +300,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); @@ -347,10 +346,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)]); } @@ -359,7 +355,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; |