aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorprovokateurin <kate@provokateurin.de>2024-09-19 18:18:54 +0200
committerprovokateurin <kate@provokateurin.de>2024-09-26 17:29:48 +0200
commit1302b48ca24419649cebd8bfa0810f9517a55484 (patch)
treecaff02fdd8d808a9a9250bf259d0638177f96c8a /apps
parent376d5665bb56d9bdf04825c174381ad116d91727 (diff)
downloadnextcloud-server-1302b48ca24419649cebd8bfa0810f9517a55484.tar.gz
nextcloud-server-1302b48ca24419649cebd8bfa0810f9517a55484.zip
fix(files_external): Fix all IStorage return types
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/lib/Lib/Storage/AmazonS3.php75
-rw-r--r--apps/files_external/lib/Lib/Storage/FTP.php31
-rw-r--r--apps/files_external/lib/Lib/Storage/OwnCloud.php2
-rw-r--r--apps/files_external/lib/Lib/Storage/SFTP.php107
-rw-r--r--apps/files_external/lib/Lib/Storage/SMB.php80
-rw-r--r--apps/files_external/lib/Lib/Storage/StreamWrapper.php22
-rw-r--r--apps/files_external/lib/Lib/Storage/Swift.php45
7 files changed, 130 insertions, 232 deletions
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php
index 5325b25a66b..b2d6d24db5e 100644
--- a/apps/files_external/lib/Lib/Storage/AmazonS3.php
+++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php
@@ -28,7 +28,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
private LoggerInterface $logger;
- public function needsPartFile() {
+ public function needsPartFile(): bool {
return false;
}
@@ -63,7 +63,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
* @param string $path
* @return string correctly encoded path
*/
- private function normalizePath($path) {
+ private function normalizePath($path): string {
$path = trim($path, '/');
if (!$path) {
@@ -73,24 +73,24 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return $path;
}
- private function isRoot($path) {
+ private function isRoot($path): bool {
return $path === '.';
}
- private function cleanKey($path) {
+ private function cleanKey($path): string {
if ($this->isRoot($path)) {
return '/';
}
return $path;
}
- private function clearCache() {
+ private function clearCache(): void {
$this->objectCache = new CappedMemoryCache();
$this->directoryCache = new CappedMemoryCache();
$this->filesCache = new CappedMemoryCache();
}
- private function invalidateCache($key) {
+ private function invalidateCache($key): void {
unset($this->objectCache[$key]);
$keys = array_keys($this->objectCache->getData());
$keyLength = strlen($key);
@@ -110,10 +110,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
unset($this->directoryCache[$key]);
}
- /**
- * @return array|false
- */
- private function headObject(string $key) {
+ private function headObject(string $key): array|false {
if (!isset($this->objectCache[$key])) {
try {
$this->objectCache[$key] = $this->getConnection()->headObject([
@@ -144,11 +141,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
* Implementation from flysystem-aws-s3-v3:
* https://github.com/thephpleague/flysystem-aws-s3-v3/blob/8241e9cc5b28f981e0d24cdaf9867f14c7498ae4/src/AwsS3Adapter.php#L670-L694
*
- * @param $path
- * @return bool
* @throws \Exception
*/
- private function doesDirectoryExist($path) {
+ private function doesDirectoryExist($path): bool {
if ($path === '.' || $path === '') {
return true;
}
@@ -190,13 +185,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
- /**
- * Remove a file or folder
- *
- * @param string $path
- * @return bool
- */
- protected function remove($path) {
+ protected function remove($path): bool {
// remember fileType to reduce http calls
$fileType = $this->filetype($path);
if ($fileType === 'dir') {
@@ -208,7 +197,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
}
- public function mkdir($path) {
+ public function mkdir($path): bool {
$path = $this->normalizePath($path);
if ($this->is_dir($path)) {
@@ -236,12 +225,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return true;
}
- public function file_exists($path) {
+ public function file_exists($path): bool {
return $this->filetype($path) !== false;
}
- public function rmdir($path) {
+ public function rmdir($path): bool {
$path = $this->normalizePath($path);
if ($this->isRoot($path)) {
@@ -256,12 +245,12 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return $this->batchDelete($path);
}
- protected function clearBucket() {
+ protected function clearBucket(): bool {
$this->clearCache();
return $this->batchDelete();
}
- private function batchDelete($path = null) {
+ private function batchDelete($path = null): bool {
// TODO explore using https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.BatchDelete.html
$params = [
'Bucket' => $this->bucket
@@ -312,7 +301,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
}
- public function stat($path) {
+ public function stat($path): array|false {
$path = $this->normalizePath($path);
if ($this->is_dir($path)) {
@@ -334,11 +323,8 @@ class AmazonS3 extends \OC\Files\Storage\Common {
*
* When the information is already present (e.g. opendir has been called before)
* this value is return. Otherwise a headObject is emitted.
- *
- * @param $path
- * @return int|mixed
*/
- private function getContentLength($path) {
+ private function getContentLength($path): int {
if (isset($this->filesCache[$path])) {
return (int)$this->filesCache[$path]['ContentLength'];
}
@@ -356,11 +342,8 @@ class AmazonS3 extends \OC\Files\Storage\Common {
*
* When the information is already present (e.g. opendir has been called before)
* this value is return. Otherwise a headObject is emitted.
- *
- * @param $path
- * @return mixed|string
*/
- private function getLastModified($path) {
+ private function getLastModified($path): string {
if (isset($this->filesCache[$path])) {
return $this->filesCache[$path]['LastModified'];
}
@@ -373,7 +356,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return 'now';
}
- public function is_dir($path) {
+ public function is_dir($path): bool {
$path = $this->normalizePath($path);
if (isset($this->filesCache[$path])) {
@@ -391,7 +374,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
}
- public function filetype($path) {
+ public function filetype($path): string|false {
$path = $this->normalizePath($path);
if ($this->isRoot($path)) {
@@ -419,7 +402,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
- public function getPermissions($path) {
+ public function getPermissions($path): int {
$type = $this->filetype($path);
if (!$type) {
return 0;
@@ -427,7 +410,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return $type === 'dir' ? Constants::PERMISSION_ALL : Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE;
}
- public function unlink($path) {
+ public function unlink($path): bool {
$path = $this->normalizePath($path);
if ($this->is_dir($path)) {
@@ -506,7 +489,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return false;
}
- public function touch($path, $mtime = null) {
+ public function touch($path, $mtime = null): bool {
if (is_null($mtime)) {
$mtime = time();
}
@@ -541,7 +524,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return true;
}
- public function copy($source, $target, $isFile = null) {
+ public function copy($source, $target, $isFile = null): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
@@ -584,7 +567,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return true;
}
- public function rename($source, $target) {
+ public function rename($source, $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
@@ -611,18 +594,18 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return true;
}
- public function test() {
+ public function test(): bool {
$this->getConnection()->headBucket([
'Bucket' => $this->bucket
]);
return true;
}
- public function getId() {
+ public function getId(): string {
return $this->id;
}
- public function writeBack($tmpFile, $path) {
+ public function writeBack($tmpFile, $path): bool {
try {
$source = fopen($tmpFile, 'r');
$this->writeObject($path, $source, $this->mimeDetector->detectPath($path));
@@ -642,7 +625,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
/**
* check if curl is installed
*/
- public static function checkDependencies() {
+ public static function checkDependencies(): bool {
return true;
}
@@ -743,7 +726,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
}
}
- public function hasUpdated($path, $time) {
+ public function hasUpdated($path, $time): bool {
// for files we can get the proper mtime
if ($path !== '' && $object = $this->headObject($path)) {
$stat = $this->objectToMetaData($object);
diff --git a/apps/files_external/lib/Lib/Storage/FTP.php b/apps/files_external/lib/Lib/Storage/FTP.php
index a7a348cbf43..514492156b6 100644
--- a/apps/files_external/lib/Lib/Storage/FTP.php
+++ b/apps/files_external/lib/Lib/Storage/FTP.php
@@ -78,15 +78,15 @@ class FTP extends Common {
return $this->connection;
}
- public function getId() {
+ public function getId(): string {
return 'ftp::' . $this->username . '@' . $this->host . '/' . $this->root;
}
- protected function buildPath($path) {
+ protected function buildPath($path): string {
return rtrim($this->root . '/' . $path, '/');
}
- public static function checkDependencies() {
+ public static function checkDependencies(): array|bool {
if (function_exists('ftp_login')) {
return true;
} else {
@@ -94,7 +94,7 @@ class FTP extends Common {
}
}
- public function filemtime($path) {
+ public function filemtime($path): int|false {
$result = $this->getConnection()->mdtm($this->buildPath($path));
if ($result === -1) {
@@ -135,7 +135,7 @@ class FTP extends Common {
}
}
- public function rmdir($path) {
+ public function rmdir($path): bool {
if ($this->is_dir($path)) {
$result = $this->getConnection()->rmdir($this->buildPath($path));
// recursive rmdir support depends on the ftp server
@@ -153,7 +153,6 @@ class FTP extends Common {
/**
* @param string $path
- * @return bool
*/
private function recursiveRmDir($path): bool {
$contents = $this->getDirectoryContent($path);
@@ -170,7 +169,7 @@ class FTP extends Common {
return $result;
}
- public function test() {
+ public function test(): bool {
try {
return $this->getConnection()->systype() !== false;
} catch (\Exception $e) {
@@ -178,7 +177,7 @@ class FTP extends Common {
}
}
- public function stat($path) {
+ public function stat($path): array|false {
if (!$this->file_exists($path)) {
return false;
}
@@ -188,14 +187,14 @@ class FTP extends Common {
];
}
- public function file_exists($path) {
+ public function file_exists($path): bool {
if ($path === '' || $path === '.' || $path === '/') {
return true;
}
return $this->filetype($path) !== false;
}
- public function unlink($path) {
+ public function unlink($path): bool {
switch ($this->filetype($path)) {
case 'dir':
return $this->rmdir($path);
@@ -211,14 +210,14 @@ class FTP extends Common {
return IteratorDirectory::wrap($files);
}
- public function mkdir($path) {
+ public function mkdir($path): bool {
if ($this->is_dir($path)) {
return false;
}
return $this->getConnection()->mkdir($this->buildPath($path)) !== false;
}
- public function is_dir($path) {
+ public function is_dir($path): bool {
if ($path === '') {
return true;
}
@@ -230,11 +229,11 @@ class FTP extends Common {
}
}
- public function is_file($path) {
+ public function is_file($path): bool {
return $this->filesize($path) !== false;
}
- public function filetype($path) {
+ public function filetype($path): string|false {
if ($this->is_dir($path)) {
return 'dir';
} elseif ($this->is_file($path)) {
@@ -310,7 +309,7 @@ class FTP extends Common {
return $stream;
}
- public function touch($path, $mtime = null) {
+ public function touch($path, $mtime = null): bool {
if ($this->file_exists($path)) {
return false;
} else {
@@ -319,7 +318,7 @@ class FTP extends Common {
}
}
- public function rename($source, $target) {
+ public function rename($source, $target): bool {
$this->unlink($target);
return $this->getConnection()->rename($this->buildPath($source), $this->buildPath($target));
}
diff --git a/apps/files_external/lib/Lib/Storage/OwnCloud.php b/apps/files_external/lib/Lib/Storage/OwnCloud.php
index fb5c7207486..5de708afb04 100644
--- a/apps/files_external/lib/Lib/Storage/OwnCloud.php
+++ b/apps/files_external/lib/Lib/Storage/OwnCloud.php
@@ -55,7 +55,7 @@ class OwnCloud extends \OC\Files\Storage\DAV implements IDisableEncryptionStorag
parent::__construct($params);
}
- public function needsPartFile() {
+ public function needsPartFile(): bool {
return false;
}
}
diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php
index a6a28245214..c8e01a058ff 100644
--- a/apps/files_external/lib/Lib/Storage/SFTP.php
+++ b/apps/files_external/lib/Lib/Storage/SFTP.php
@@ -39,7 +39,7 @@ class SFTP extends Common {
* @param string $host protocol://server:port
* @return array [$server, $port]
*/
- private function splitHost($host) {
+ private function splitHost($host): array {
$input = $host;
if (!str_contains($host, '://')) {
// add a protocol to fix parse_url behavior with ipv6
@@ -56,9 +56,6 @@ class SFTP extends Common {
}
}
- /**
- * {@inheritdoc}
- */
public function __construct($params) {
// Register sftp://
Stream::register();
@@ -98,7 +95,7 @@ class SFTP extends Common {
* @return \phpseclib\Net\SFTP connected client instance
* @throws \Exception when the connection failed
*/
- public function getConnection() {
+ public function getConnection(): \phpseclib\Net\SFTP {
if (!is_null($this->client)) {
return $this->client;
}
@@ -132,10 +129,7 @@ class SFTP extends Common {
return $this->client;
}
- /**
- * {@inheritdoc}
- */
- public function test() {
+ public function test(): bool {
if (
!isset($this->host)
|| !isset($this->user)
@@ -145,10 +139,7 @@ class SFTP extends Common {
return $this->getConnection()->nlist() !== false;
}
- /**
- * {@inheritdoc}
- */
- public function getId() {
+ public function getId(): string {
$id = 'sftp::' . $this->user . '@' . $this->host;
if ($this->port !== 22) {
$id .= ':' . $this->port;
@@ -160,39 +151,26 @@ class SFTP extends Common {
return $id;
}
- /**
- * @return string
- */
- public function getHost() {
+ public function getHost(): string {
return $this->host;
}
- /**
- * @return string
- */
- public function getRoot() {
+ public function getRoot(): string {
return $this->root;
}
- /**
- * @return mixed
- */
- public function getUser() {
+ public function getUser(): string {
return $this->user;
}
/**
* @param string $path
- * @return string
*/
- private function absPath($path) {
+ private function absPath($path): string {
return $this->root . $this->cleanPath($path);
}
- /**
- * @return string|false
- */
- private function hostKeysPath() {
+ private function hostKeysPath(): string|false {
try {
$userId = \OC_User::getUser();
if ($userId === false) {
@@ -207,11 +185,7 @@ class SFTP extends Common {
return false;
}
- /**
- * @param $keys
- * @return bool
- */
- protected function writeHostKeys($keys) {
+ protected function writeHostKeys($keys): bool {
try {
$keyPath = $this->hostKeysPath();
if ($keyPath && file_exists($keyPath)) {
@@ -227,10 +201,7 @@ class SFTP extends Common {
return false;
}
- /**
- * @return array
- */
- protected function readHostKeys() {
+ protected function readHostKeys(): array {
try {
$keyPath = $this->hostKeysPath();
if (file_exists($keyPath)) {
@@ -253,10 +224,7 @@ class SFTP extends Common {
return [];
}
- /**
- * {@inheritdoc}
- */
- public function mkdir($path) {
+ public function mkdir($path): bool {
try {
return $this->getConnection()->mkdir($this->absPath($path));
} catch (\Exception $e) {
@@ -264,10 +232,7 @@ class SFTP extends Common {
}
}
- /**
- * {@inheritdoc}
- */
- public function rmdir($path) {
+ public function rmdir($path): bool {
try {
$result = $this->getConnection()->delete($this->absPath($path), true);
// workaround: stray stat cache entry when deleting empty folders
@@ -279,9 +244,6 @@ class SFTP extends Common {
}
}
- /**
- * {@inheritdoc}
- */
public function opendir($path) {
try {
$list = $this->getConnection()->nlist($this->absPath($path));
@@ -302,10 +264,7 @@ class SFTP extends Common {
}
}
- /**
- * {@inheritdoc}
- */
- public function filetype($path) {
+ public function filetype($path): string|false {
try {
$stat = $this->getConnection()->stat($this->absPath($path));
if (!is_array($stat) || !array_key_exists('type', $stat)) {
@@ -323,10 +282,7 @@ class SFTP extends Common {
return false;
}
- /**
- * {@inheritdoc}
- */
- public function file_exists($path) {
+ public function file_exists($path): bool {
try {
return $this->getConnection()->stat($this->absPath($path)) !== false;
} catch (\Exception $e) {
@@ -334,10 +290,7 @@ class SFTP extends Common {
}
}
- /**
- * {@inheritdoc}
- */
- public function unlink($path) {
+ public function unlink($path): bool {
try {
return $this->getConnection()->delete($this->absPath($path), true);
} catch (\Exception $e) {
@@ -345,9 +298,6 @@ class SFTP extends Common {
}
}
- /**
- * {@inheritdoc}
- */
public function fopen($path, $mode) {
try {
$absPath = $this->absPath($path);
@@ -389,10 +339,7 @@ class SFTP extends Common {
return false;
}
- /**
- * {@inheritdoc}
- */
- public function touch($path, $mtime = null) {
+ public function touch($path, $mtime = null): bool {
try {
if (!is_null($mtime)) {
return false;
@@ -413,14 +360,11 @@ class SFTP extends Common {
* @param string $target
* @throws \Exception
*/
- public function getFile($path, $target) {
+ public function getFile($path, $target): void {
$this->getConnection()->get($path, $target);
}
- /**
- * {@inheritdoc}
- */
- public function rename($source, $target) {
+ public function rename($source, $target): bool {
try {
if ($this->file_exists($target)) {
$this->unlink($target);
@@ -437,7 +381,7 @@ class SFTP extends Common {
/**
* @return array{mtime: int, size: int, ctime: int}|false
*/
- public function stat($path) {
+ public function stat($path): array|false {
try {
$stat = $this->getConnection()->stat($this->absPath($path));
@@ -456,9 +400,8 @@ class SFTP extends Common {
/**
* @param string $path
- * @return string
*/
- public function constructUrl($path) {
+ public function constructUrl($path): string {
// Do not pass the password here. We want to use the Net_SFTP object
// supplied via stream context or fail. We only supply username and
// hostname because this might show up in logs (they are not used).
@@ -466,7 +409,7 @@ class SFTP extends Common {
return $url;
}
- public function file_put_contents($path, $data) {
+ public function file_put_contents($path, $data): int|float|false {
/** @psalm-suppress InternalMethod */
$result = $this->getConnection()->put($this->absPath($path), $data);
if ($result) {
@@ -498,7 +441,7 @@ class SFTP extends Common {
}
}
- public function copy($source, $target) {
+ public function copy($source, $target): bool {
if ($this->is_dir($source) || $this->is_dir($target)) {
return parent::copy($source, $target);
} else {
@@ -525,7 +468,7 @@ class SFTP extends Common {
}
}
- public function getPermissions($path) {
+ public function getPermissions($path): int {
$stat = $this->getConnection()->stat($this->absPath($path));
if (!$stat) {
return 0;
@@ -537,7 +480,7 @@ class SFTP extends Common {
}
}
- public function getMetaData($path) {
+ public function getMetaData($path): ?array {
$stat = $this->getConnection()->stat($this->absPath($path));
if (!$stat) {
return null;
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php
index 91a6eab8d09..4f1f51f1bf9 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -118,7 +118,7 @@ class SMB extends Common implements INotifyStorage {
parent::__construct($params);
}
- private function splitUser($user) {
+ private function splitUser($user): array {
if (str_contains($user, '/')) {
return explode('/', $user, 2);
} elseif (str_contains($user, '\\')) {
@@ -128,10 +128,7 @@ class SMB extends Common implements INotifyStorage {
return [null, $user];
}
- /**
- * @return string
- */
- public function getId() {
+ public function getId(): string {
// FIXME: double slash to keep compatible with the old storage ids,
// failure to do so will lead to creation of a new storage id and
// loss of shares from the storage
@@ -140,13 +137,12 @@ class SMB extends Common implements INotifyStorage {
/**
* @param string $path
- * @return string
*/
- protected function buildPath($path) {
+ protected function buildPath($path): string {
return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
}
- protected function relativePath($fullPath) {
+ protected function relativePath($fullPath): ?string {
if ($fullPath === $this->root) {
return '';
} elseif (substr($fullPath, 0, strlen($this->root)) === $this->root) {
@@ -158,12 +154,11 @@ class SMB extends Common implements INotifyStorage {
/**
* @param string $path
- * @return IFileInfo
* @throws StorageAuthException
* @throws \OCP\Files\NotFoundException
* @throws \OCP\Files\ForbiddenException
*/
- protected function getFileInfo($path) {
+ protected function getFileInfo($path): IFileInfo {
try {
$path = $this->buildPath($path);
$cached = $this->statCache[$path] ?? null;
@@ -190,10 +185,9 @@ class SMB extends Common implements INotifyStorage {
/**
* @param \Exception $e
- * @return never
* @throws StorageAuthException
*/
- protected function throwUnavailable(\Exception $e) {
+ protected function throwUnavailable(\Exception $e): never {
$this->logger->error('Error while getting file info', ['exception' => $e]);
throw new StorageAuthException($e->getMessage(), $e);
}
@@ -202,7 +196,6 @@ class SMB extends Common implements INotifyStorage {
* get the acl from fileinfo that is relevant for the configured user
*
* @param IFileInfo $file
- * @return ACL|null
*/
private function getACL(IFileInfo $file): ?ACL {
$acls = $file->getAcls();
@@ -274,9 +267,8 @@ class SMB extends Common implements INotifyStorage {
/**
* @param IFileInfo $info
- * @return array
*/
- protected function formatInfo($info) {
+ protected function formatInfo($info): array {
$result = [
'size' => $info->getSize(),
'mtime' => $info->getMTime(),
@@ -294,7 +286,6 @@ class SMB extends Common implements INotifyStorage {
*
* @param string $source the old name of the path
* @param string $target the new name of the path
- * @return bool true if the rename is successful, false otherwise
*/
public function rename($source, $target, $retry = true): bool {
if ($this->isRootDir($source) || $this->isRootDir($target)) {
@@ -335,7 +326,7 @@ class SMB extends Common implements INotifyStorage {
return $result;
}
- public function stat($path, $retry = true) {
+ public function stat($path, $retry = true): array|false {
try {
$result = $this->formatInfo($this->getFileInfo($path));
} catch (\OCP\Files\ForbiddenException $e) {
@@ -357,10 +348,8 @@ class SMB extends Common implements INotifyStorage {
/**
* get the best guess for the modification time of the share
- *
- * @return int
*/
- private function shareMTime() {
+ private function shareMTime(): int {
$highestMTime = 0;
$files = $this->share->dir($this->root);
foreach ($files as $fileInfo) {
@@ -381,26 +370,22 @@ class SMB extends Common implements INotifyStorage {
* Check if the path is our root dir (not the smb one)
*
* @param string $path the path
- * @return bool
*/
- private function isRootDir($path) {
+ private function isRootDir($path): bool {
return $path === '' || $path === '/' || $path === '.';
}
/**
* Check if our root points to a smb share
- *
- * @return bool true if our root points to a share false otherwise
*/
- private function remoteIsShare() {
+ private function remoteIsShare(): bool {
return $this->share->getName() && (!$this->root || $this->root === '/');
}
/**
* @param string $path
- * @return bool
*/
- public function unlink($path) {
+ public function unlink($path): bool {
if ($this->isRootDir($path)) {
return false;
}
@@ -429,9 +414,8 @@ class SMB extends Common implements INotifyStorage {
*
* @param string $path
* @param int $time
- * @return bool
*/
- public function hasUpdated($path, $time) {
+ public function hasUpdated($path, $time): bool {
if (!$path and $this->root === '/') {
// mtime doesn't work for shares, but giving the nature of the backend,
// doing a full update is still just fast enough
@@ -445,7 +429,7 @@ class SMB extends Common implements INotifyStorage {
/**
* @param string $path
* @param string $mode
- * @return resource|bool
+ * @return resource|false
*/
public function fopen($path, $mode) {
$fullPath = $this->buildPath($path);
@@ -511,7 +495,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function rmdir($path) {
+ public function rmdir($path): bool {
if ($this->isRootDir($path)) {
return false;
}
@@ -538,7 +522,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function touch($path, $mtime = null) {
+ public function touch($path, $mtime = null): bool {
try {
if (!$this->file_exists($path)) {
$fh = $this->share->write($this->buildPath($path));
@@ -554,7 +538,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function getMetaData($path) {
+ public function getMetaData($path): ?array {
try {
$fileInfo = $this->getFileInfo($path);
} catch (\OCP\Files\NotFoundException $e) {
@@ -562,14 +546,11 @@ class SMB extends Common implements INotifyStorage {
} catch (\OCP\Files\ForbiddenException $e) {
return null;
}
- if (!$fileInfo) {
- return null;
- }
return $this->getMetaDataFromFileInfo($fileInfo);
}
- private function getMetaDataFromFileInfo(IFileInfo $fileInfo) {
+ private function getMetaDataFromFileInfo(IFileInfo $fileInfo): array {
$permissions = Constants::PERMISSION_READ + Constants::PERMISSION_SHARE;
if (
@@ -630,7 +611,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function filetype($path) {
+ public function filetype($path): string|false {
try {
return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file';
} catch (\OCP\Files\NotFoundException $e) {
@@ -640,7 +621,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function mkdir($path) {
+ public function mkdir($path): bool {
$path = $this->buildPath($path);
try {
$this->share->mkdir($path);
@@ -653,7 +634,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function file_exists($path) {
+ public function file_exists($path): bool {
try {
// Case sensitive filesystem doesn't matter for root directory
if ($this->caseSensitive === false && $path !== '') {
@@ -677,7 +658,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function isReadable($path) {
+ public function isReadable($path): bool {
try {
$info = $this->getFileInfo($path);
return $this->showHidden || !$info->isHidden();
@@ -688,7 +669,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function isUpdatable($path) {
+ public function isUpdatable($path): bool {
try {
$info = $this->getFileInfo($path);
// following windows behaviour for read-only folders: they can be written into
@@ -701,7 +682,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function isDeletable($path) {
+ public function isDeletable($path): bool {
try {
$info = $this->getFileInfo($path);
return ($this->showHidden || !$info->isHidden()) && !$info->isReadOnly();
@@ -715,19 +696,14 @@ class SMB extends Common implements INotifyStorage {
/**
* check if smbclient is installed
*/
- public static function checkDependencies() {
+ public static function checkDependencies(): array|bool {
return (
(bool)\OC_Helper::findBinaryPath('smbclient')
|| NativeServer::available(new System())
) ? true : ['smbclient'];
}
- /**
- * Test a storage for availability
- *
- * @return bool
- */
- public function test() {
+ public function test(): bool {
try {
return parent::test();
} catch (StorageAuthException $e) {
@@ -740,7 +716,7 @@ class SMB extends Common implements INotifyStorage {
}
}
- public function listen($path, callable $callback) {
+ public function listen($path, callable $callback): void {
$this->notify($path)->listen(function (IChange $change) use ($callback) {
if ($change instanceof IRenameChange) {
return $callback($change->getType(), $change->getPath(), $change->getTargetPath());
@@ -750,7 +726,7 @@ class SMB extends Common implements INotifyStorage {
});
}
- public function notify($path) {
+ public function notify($path): SMBNotifyHandler {
$path = '/' . ltrim($path, '/');
$shareNotifyHandler = $this->share->notify($this->buildPath($path));
return new SMBNotifyHandler($shareNotifyHandler, $this->root);
diff --git a/apps/files_external/lib/Lib/Storage/StreamWrapper.php b/apps/files_external/lib/Lib/Storage/StreamWrapper.php
index 2928c081505..96a306e4f53 100644
--- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php
+++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php
@@ -12,13 +12,13 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common {
* @param string $path
* @return string|null
*/
- abstract public function constructUrl($path);
+ abstract public function constructUrl($path): ?string;
- public function mkdir($path) {
+ public function mkdir($path): bool {
return mkdir($this->constructUrl($path));
}
- public function rmdir($path) {
+ public function rmdir($path): bool {
if ($this->is_dir($path) && $this->isDeletable($path)) {
$dh = $this->opendir($path);
if (!is_resource($dh)) {
@@ -44,15 +44,15 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common {
return opendir($this->constructUrl($path));
}
- public function filetype($path) {
+ public function filetype($path): string|false {
return @filetype($this->constructUrl($path));
}
- public function file_exists($path) {
+ public function file_exists($path): bool {
return file_exists($this->constructUrl($path));
}
- public function unlink($path) {
+ public function unlink($path): bool {
$url = $this->constructUrl($path);
$success = unlink($url);
// normally unlink() is supposed to do this implicitly,
@@ -65,7 +65,7 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common {
return fopen($this->constructUrl($path), $mode);
}
- public function touch($path, $mtime = null) {
+ public function touch($path, $mtime = null): bool {
if ($this->file_exists($path)) {
if (is_null($mtime)) {
$fh = $this->fopen($path, 'a');
@@ -86,22 +86,22 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common {
* @param string $path
* @param string $target
*/
- public function getFile($path, $target) {
+ public function getFile($path, $target): bool {
return copy($this->constructUrl($path), $target);
}
/**
* @param string $target
*/
- public function uploadFile($path, $target) {
+ public function uploadFile($path, $target): bool {
return copy($path, $this->constructUrl($target));
}
- public function rename($source, $target) {
+ public function rename($source, $target): bool {
return rename($this->constructUrl($source), $this->constructUrl($target));
}
- public function stat($path) {
+ public function stat($path): array|false {
return stat($this->constructUrl($path));
}
}
diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php
index 9aabf5b56b4..3582470b3be 100644
--- a/apps/files_external/lib/Lib/Storage/Swift.php
+++ b/apps/files_external/lib/Lib/Storage/Swift.php
@@ -16,6 +16,7 @@ use OC\Files\ObjectStore\SwiftFactory;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\StorageBadConfigException;
use OpenStack\Common\Error\BadResponseError;
+use OpenStack\ObjectStore\v1\Models\Container;
use OpenStack\ObjectStore\v1\Models\StorageObject;
use Psr\Log\LoggerInterface;
@@ -23,7 +24,7 @@ class Swift extends \OC\Files\Storage\Common {
/** @var SwiftFactory */
private $connectionFactory;
/**
- * @var \OpenStack\ObjectStore\v1\Models\Container
+ * @var Container
*/
private $container;
/**
@@ -55,11 +56,7 @@ class Swift extends \OC\Files\Storage\Common {
*/
private $objectCache;
- /**
- * @param string $path
- * @return mixed|string
- */
- private function normalizePath(string $path) {
+ private function normalizePath(string $path): string {
$path = trim($path, '/');
if (!$path) {
@@ -87,12 +84,12 @@ class Swift extends \OC\Files\Storage\Common {
* that one will be returned.
*
* @param string $path
- * @return StorageObject|bool object
- * or false if the object did not exist
+ * @return StorageObject|false object
+ * or false if the object did not exist
* @throws \OCP\Files\StorageAuthException
* @throws \OCP\Files\StorageNotAvailableException
*/
- private function fetchObject(string $path) {
+ private function fetchObject(string $path): StorageObject|false {
$cached = $this->objectCache->get($path);
if ($cached !== null) {
// might be "false" if object did not exist from last check
@@ -125,7 +122,7 @@ class Swift extends \OC\Files\Storage\Common {
* @throws \OCP\Files\StorageAuthException
* @throws \OCP\Files\StorageNotAvailableException
*/
- private function doesObjectExist($path) {
+ private function doesObjectExist($path): bool {
return $this->fetchObject($path) !== false;
}
@@ -179,7 +176,7 @@ class Swift extends \OC\Files\Storage\Common {
$this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class);
}
- public function mkdir($path) {
+ public function mkdir($path): bool {
$path = $this->normalizePath($path);
if ($this->is_dir($path)) {
@@ -210,7 +207,7 @@ class Swift extends \OC\Files\Storage\Common {
return true;
}
- public function file_exists($path) {
+ public function file_exists($path): bool {
$path = $this->normalizePath($path);
if ($path !== '.' && $this->is_dir($path)) {
@@ -220,7 +217,7 @@ class Swift extends \OC\Files\Storage\Common {
return $this->doesObjectExist($path);
}
- public function rmdir($path) {
+ public function rmdir($path): bool {
$path = $this->normalizePath($path);
if (!$this->is_dir($path) || !$this->isDeletable($path)) {
@@ -290,7 +287,7 @@ class Swift extends \OC\Files\Storage\Common {
}
}
- public function stat($path) {
+ public function stat($path): array|false {
$path = $this->normalizePath($path);
if ($path === '.') {
@@ -346,7 +343,7 @@ class Swift extends \OC\Files\Storage\Common {
}
}
- public function unlink($path) {
+ public function unlink($path): bool {
$path = $this->normalizePath($path);
if ($this->is_dir($path)) {
@@ -420,7 +417,7 @@ class Swift extends \OC\Files\Storage\Common {
}
}
- public function touch($path, $mtime = null) {
+ public function touch($path, $mtime = null): bool {
$path = $this->normalizePath($path);
if (is_null($mtime)) {
$mtime = time();
@@ -450,7 +447,7 @@ class Swift extends \OC\Files\Storage\Common {
}
}
- public function copy($source, $target) {
+ public function copy($source, $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
@@ -511,7 +508,7 @@ class Swift extends \OC\Files\Storage\Common {
return true;
}
- public function rename($source, $target) {
+ public function rename($source, $target): bool {
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);
@@ -536,18 +533,18 @@ class Swift extends \OC\Files\Storage\Common {
return false;
}
- public function getId() {
+ public function getId(): string {
return $this->id;
}
/**
* Returns the initialized object store container.
*
- * @return \OpenStack\ObjectStore\v1\Models\Container
+ * @return Container
* @throws \OCP\Files\StorageAuthException
* @throws \OCP\Files\StorageNotAvailableException
*/
- public function getContainer() {
+ public function getContainer(): Container {
if (is_null($this->container)) {
$this->container = $this->connectionFactory->getContainer();
@@ -558,7 +555,7 @@ class Swift extends \OC\Files\Storage\Common {
return $this->container;
}
- public function writeBack($tmpFile, $path) {
+ public function writeBack($tmpFile, $path): void {
$fileData = fopen($tmpFile, 'r');
$this->objectStore->writeObject($path, $fileData, $this->mimeDetector->detectPath($path));
// invalidate target object to force repopulation on fetch
@@ -566,7 +563,7 @@ class Swift extends \OC\Files\Storage\Common {
unlink($tmpFile);
}
- public function hasUpdated($path, $time) {
+ public function hasUpdated($path, $time): bool {
if ($this->is_file($path)) {
return parent::hasUpdated($path, $time);
}
@@ -591,7 +588,7 @@ class Swift extends \OC\Files\Storage\Common {
/**
* check if curl is installed
*/
- public static function checkDependencies() {
+ public static function checkDependencies(): bool {
return true;
}
}