summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Lib')
-rw-r--r--apps/files_external/lib/Lib/Auth/AuthMechanism.php4
-rw-r--r--apps/files_external/lib/Lib/Backend/Backend.php17
-rw-r--r--apps/files_external/lib/Lib/FrontendDefinitionTrait.php54
-rw-r--r--apps/files_external/lib/Lib/IFrontendDefinition.php56
-rw-r--r--apps/files_external/lib/Lib/IIdentifier.php27
-rw-r--r--apps/files_external/lib/Lib/IdentifierTrait.php44
-rw-r--r--apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php6
-rw-r--r--apps/files_external/lib/Lib/MissingDependency.php10
-rw-r--r--apps/files_external/lib/Lib/PriorityTrait.php9
-rw-r--r--apps/files_external/lib/Lib/Storage/AmazonS3.php109
-rw-r--r--apps/files_external/lib/Lib/Storage/FTP.php6
-rw-r--r--apps/files_external/lib/Lib/Storage/FtpConnection.php4
-rw-r--r--apps/files_external/lib/Lib/Storage/SFTPReadStream.php4
-rw-r--r--apps/files_external/lib/Lib/Storage/SFTPWriteStream.php4
-rw-r--r--apps/files_external/lib/Lib/Storage/SMB.php20
-rw-r--r--apps/files_external/lib/Lib/Storage/StreamWrapper.php4
-rw-r--r--apps/files_external/lib/Lib/Storage/Swift.php50
-rw-r--r--apps/files_external/lib/Lib/StorageConfig.php8
18 files changed, 244 insertions, 192 deletions
diff --git a/apps/files_external/lib/Lib/Auth/AuthMechanism.php b/apps/files_external/lib/Lib/Auth/AuthMechanism.php
index 929068ea7ef..e43f6d06b47 100644
--- a/apps/files_external/lib/Lib/Auth/AuthMechanism.php
+++ b/apps/files_external/lib/Lib/Auth/AuthMechanism.php
@@ -29,6 +29,8 @@ use OCA\Files_External\Lib\IdentifierTrait;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Lib\StorageModifierTrait;
use OCA\Files_External\Lib\VisibilityTrait;
+use OCA\Files_External\Lib\IIdentifier;
+use OCA\Files_External\Lib\IFrontendDefinition;
/**
* Authentication mechanism
@@ -50,7 +52,7 @@ use OCA\Files_External\Lib\VisibilityTrait;
* - StorageModifierTrait
* Object can affect storage mounting
*/
-class AuthMechanism implements \JsonSerializable {
+class AuthMechanism implements \JsonSerializable, IIdentifier, IFrontendDefinition {
/** Standard authentication schemes */
public const SCHEME_NULL = 'null';
public const SCHEME_BUILTIN = 'builtin';
diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php
index 053d9b87952..d0058e98b52 100644
--- a/apps/files_external/lib/Lib/Backend/Backend.php
+++ b/apps/files_external/lib/Lib/Backend/Backend.php
@@ -30,6 +30,9 @@ use OCA\Files_External\Lib\PriorityTrait;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Lib\StorageModifierTrait;
use OCA\Files_External\Lib\VisibilityTrait;
+use OCA\Files_External\Lib\IIdentifier;
+use OCA\Files_External\Lib\IFrontendDefinition;
+use OCP\Files\Storage\IStorage;
/**
* Storage backend
@@ -55,7 +58,7 @@ use OCA\Files_External\Lib\VisibilityTrait;
* - StorageModifierTrait
* Object can affect storage mounting
*/
-class Backend implements \JsonSerializable {
+class Backend implements \JsonSerializable, IIdentifier, IFrontendDefinition {
use VisibilityTrait;
use FrontendDefinitionTrait;
use PriorityTrait;
@@ -73,7 +76,7 @@ class Backend implements \JsonSerializable {
private $legacyAuthMechanism;
/**
- * @return string
+ * @return class-string<IStorage>
*/
public function getStorageClass() {
return $this->storageClass;
@@ -118,21 +121,17 @@ class Backend implements \JsonSerializable {
return $this->legacyAuthMechanism;
}
- /**
- * @param AuthMechanism $authMechanism
- * @return self
- */
- public function setLegacyAuthMechanism(AuthMechanism $authMechanism) {
+ public function setLegacyAuthMechanism(AuthMechanism $authMechanism): self {
$this->legacyAuthMechanism = $authMechanism;
return $this;
}
/**
* @param callable $callback dynamic auth mechanism selection
- * @return self
*/
- public function setLegacyAuthMechanismCallback(callable $callback) {
+ public function setLegacyAuthMechanismCallback(callable $callback): self {
$this->legacyAuthMechanism = $callback;
+ return $this;
}
/**
diff --git a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
index b10d3a0b276..fd72b2fa7aa 100644
--- a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
+++ b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
@@ -29,62 +29,45 @@ namespace OCA\Files_External\Lib;
trait FrontendDefinitionTrait {
/** @var string human-readable mechanism name */
- private $text;
+ private string $text = "";
- /** @var DefinitionParameter[] parameters for mechanism */
- private $parameters = [];
+ /** @var array<string, DefinitionParameter> parameters for mechanism */
+ private array $parameters = [];
/** @var string[] custom JS */
- private $customJs = [];
+ private array $customJs = [];
- /**
- * @return string
- */
- public function getText() {
+ public function getText(): string {
return $this->text;
}
- /**
- * @param string $text
- * @return $this
- */
- public function setText($text) {
+ public function setText(string $text): self {
$this->text = $text;
return $this;
}
- /**
- * @param FrontendDefinitionTrait $a
- * @param FrontendDefinitionTrait $b
- * @return int
- */
- public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) {
+ public static function lexicalCompare(IFrontendDefinition $a, IFrontendDefinition $b): int {
return strcmp($a->getText(), $b->getText());
}
/**
- * @return DefinitionParameter[]
+ * @return array<string, DefinitionParameter>
*/
- public function getParameters() {
+ public function getParameters(): array {
return $this->parameters;
}
/**
- * @param DefinitionParameter[] $parameters
- * @return self
+ * @param list<DefinitionParameter> $parameters
*/
- public function addParameters(array $parameters) {
+ public function addParameters(array $parameters): self {
foreach ($parameters as $parameter) {
$this->addParameter($parameter);
}
return $this;
}
- /**
- * @param DefinitionParameter $parameter
- * @return self
- */
- public function addParameter(DefinitionParameter $parameter) {
+ public function addParameter(DefinitionParameter $parameter): self {
$this->parameters[$parameter->getName()] = $parameter;
return $this;
}
@@ -92,7 +75,7 @@ trait FrontendDefinitionTrait {
/**
* @return string[]
*/
- public function getCustomJs() {
+ public function getCustomJs(): array {
return $this->customJs;
}
@@ -100,17 +83,15 @@ trait FrontendDefinitionTrait {
* @param string $custom
* @return self
*/
- public function addCustomJs($custom) {
+ public function addCustomJs(string $custom): self {
$this->customJs[] = $custom;
return $this;
}
/**
* Serialize into JSON for client-side JS
- *
- * @return array
*/
- public function jsonSerializeDefinition() {
+ public function jsonSerializeDefinition(): array {
$configuration = [];
foreach ($this->getParameters() as $parameter) {
$configuration[$parameter->getName()] = $parameter;
@@ -126,11 +107,8 @@ trait FrontendDefinitionTrait {
/**
* Check if parameters are satisfied in a StorageConfig
- *
- * @param StorageConfig $storage
- * @return bool
*/
- public function validateStorageDefinition(StorageConfig $storage) {
+ public function validateStorageDefinition(StorageConfig $storage): bool {
foreach ($this->getParameters() as $name => $parameter) {
$value = $storage->getBackendOption($name);
if (!is_null($value) || !$parameter->isOptional()) {
diff --git a/apps/files_external/lib/Lib/IFrontendDefinition.php b/apps/files_external/lib/Lib/IFrontendDefinition.php
new file mode 100644
index 00000000000..3c625c21c15
--- /dev/null
+++ b/apps/files_external/lib/Lib/IFrontendDefinition.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * 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/>
+ *
+ */
+namespace OCA\Files_External\Lib;
+
+interface IFrontendDefinition {
+
+ public function getText(): string;
+
+ public function setText(string $text): self;
+
+ /**
+ * @return array<string, DefinitionParameter>
+ */
+ public function getParameters(): array;
+
+ /**
+ * @param list<DefinitionParameter> $parameters
+ */
+ public function addParameters(array $parameters): self;
+
+ public function addParameter(DefinitionParameter $parameter): self;
+
+ /**
+ * @return string[]
+ */
+ public function getCustomJs(): array;
+
+ public function addCustomJs(string $custom): self;
+
+ /**
+ * Serialize into JSON for client-side JS
+ */
+ public function jsonSerializeDefinition(): array;
+
+ /**
+ * Check if parameters are satisfied in a StorageConfig
+ */
+ public function validateStorageDefinition(StorageConfig $storage): bool;
+}
diff --git a/apps/files_external/lib/Lib/IIdentifier.php b/apps/files_external/lib/Lib/IIdentifier.php
new file mode 100644
index 00000000000..b410f5333d5
--- /dev/null
+++ b/apps/files_external/lib/Lib/IIdentifier.php
@@ -0,0 +1,27 @@
+<?php
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * 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/>
+ *
+ */
+namespace OCA\Files_External\Lib;
+
+interface IIdentifier {
+
+ public function getIdentifier(): string;
+
+ public function setIdentifier(string $identifier): self;
+}
diff --git a/apps/files_external/lib/Lib/IdentifierTrait.php b/apps/files_external/lib/Lib/IdentifierTrait.php
index 37813795490..52eff147a02 100644
--- a/apps/files_external/lib/Lib/IdentifierTrait.php
+++ b/apps/files_external/lib/Lib/IdentifierTrait.php
@@ -28,27 +28,17 @@ namespace OCA\Files_External\Lib;
*/
trait IdentifierTrait {
- /** @var string */
- protected $identifier;
+ protected string $identifier = '';
/** @var string[] */
- protected $identifierAliases = [];
+ protected array $identifierAliases = [];
+ protected ?IIdentifier $deprecateTo = null;
- /** @var IdentifierTrait */
- protected $deprecateTo = null;
-
- /**
- * @return string
- */
- public function getIdentifier() {
+ public function getIdentifier(): string {
return $this->identifier;
}
- /**
- * @param string $identifier
- * @return $this
- */
- public function setIdentifier($identifier) {
+ public function setIdentifier(string $identifier): self {
$this->identifier = $identifier;
$this->identifierAliases[] = $identifier;
return $this;
@@ -57,39 +47,25 @@ trait IdentifierTrait {
/**
* @return string[]
*/
- public function getIdentifierAliases() {
+ public function getIdentifierAliases(): array {
return $this->identifierAliases;
}
- /**
- * @param string $alias
- * @return $this
- */
- public function addIdentifierAlias($alias) {
+ public function addIdentifierAlias(string $alias): self {
$this->identifierAliases[] = $alias;
return $this;
}
- /**
- * @return object|null
- */
- public function getDeprecateTo() {
+ public function getDeprecateTo(): ?IIdentifier {
return $this->deprecateTo;
}
- /**
- * @param object $destinationObject
- * @return self
- */
- public function deprecateTo($destinationObject) {
+ public function deprecateTo(IIdentifier $destinationObject): self {
$this->deprecateTo = $destinationObject;
return $this;
}
- /**
- * @return array
- */
- public function jsonSerializeIdentifier() {
+ public function jsonSerializeIdentifier(): array {
$data = [
'identifier' => $this->identifier,
'identifierAliases' => $this->identifierAliases,
diff --git a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php
index 732413c78cd..42a72e960ea 100644
--- a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php
+++ b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php
@@ -21,13 +21,15 @@
*/
namespace OCA\Files_External\Lib;
+use OCP\Files\Storage\IStorage;
+
/**
* Polyfill for checking dependencies using legacy Storage::checkDependencies()
*/
trait LegacyDependencyCheckPolyfill {
/**
- * @return string
+ * @return class-string<IStorage>
*/
abstract public function getStorageClass();
@@ -54,7 +56,7 @@ trait LegacyDependencyCheckPolyfill {
$module = $key;
$message = $value;
}
- $value = new MissingDependency($module, $this);
+ $value = new MissingDependency($module);
$value->setMessage($message);
}
$ret[] = $value;
diff --git a/apps/files_external/lib/Lib/MissingDependency.php b/apps/files_external/lib/Lib/MissingDependency.php
index b740f4596b2..a8e9f9ecc45 100644
--- a/apps/files_external/lib/Lib/MissingDependency.php
+++ b/apps/files_external/lib/Lib/MissingDependency.php
@@ -39,17 +39,11 @@ class MissingDependency {
$this->dependency = $dependency;
}
- /**
- * @return string
- */
- public function getDependency() {
+ public function getDependency(): string {
return $this->dependency;
}
- /**
- * @return string|null
- */
- public function getMessage() {
+ public function getMessage(): ?string {
return $this->message;
}
diff --git a/apps/files_external/lib/Lib/PriorityTrait.php b/apps/files_external/lib/Lib/PriorityTrait.php
index 355f75a833a..299d25c9b40 100644
--- a/apps/files_external/lib/Lib/PriorityTrait.php
+++ b/apps/files_external/lib/Lib/PriorityTrait.php
@@ -47,13 +47,4 @@ trait PriorityTrait {
$this->priority = $priority;
return $this;
}
-
- /**
- * @param PriorityTrait $a
- * @param PriorityTrait $b
- * @return int
- */
- public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) {
- return ($a->getPriority() - $b->getPriority());
- }
}
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php
index d5b8eff6fe5..9e91b89d29e 100644
--- a/apps/files_external/lib/Lib/Storage/AmazonS3.php
+++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php
@@ -55,11 +55,14 @@ use OCP\ICacheFactory;
use OCP\IMemcache;
use OCP\Server;
use OCP\ICache;
+use Psr\Log\LoggerInterface;
class AmazonS3 extends \OC\Files\Storage\Common {
use S3ConnectionTrait;
use S3ObjectTrait;
+ private LoggerInterface $logger;
+
public function needsPartFile() {
return false;
}
@@ -88,6 +91,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
/** @var ICacheFactory $cacheFactory */
$cacheFactory = Server::get(ICacheFactory::class);
$this->memCache = $cacheFactory->createLocal('s3-external');
+ $this->logger = Server::get(LoggerInterface::class);
}
/**
@@ -255,7 +259,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
]);
$this->testTimeout();
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
@@ -286,18 +293,11 @@ class AmazonS3 extends \OC\Files\Storage\Common {
protected function clearBucket() {
$this->clearCache();
- try {
- $this->getConnection()->clearBucket([
- "Bucket" => $this->bucket
- ]);
- return true;
- // clearBucket() is not working with Ceph, so if it fails we try the slower approach
- } catch (\Exception $e) {
- return $this->batchDelete();
- }
+ return $this->batchDelete();
}
private function batchDelete($path = null) {
+ // TODO explore using https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.BatchDelete.html
$params = [
'Bucket' => $this->bucket
];
@@ -327,7 +327,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$this->deleteObject($path);
}
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
return true;
@@ -415,7 +418,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
try {
return $this->doesDirectoryExist($path);
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
}
@@ -438,7 +444,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return 'dir';
}
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
@@ -464,7 +473,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$this->deleteObject($path);
$this->invalidateCache($path);
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
@@ -486,7 +498,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
try {
return $this->readObject($path);
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
case 'w':
@@ -548,7 +563,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$this->testTimeout();
}
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
@@ -556,65 +574,71 @@ class AmazonS3 extends \OC\Files\Storage\Common {
return true;
}
- public function copy($path1, $path2, $isFile = null) {
- $path1 = $this->normalizePath($path1);
- $path2 = $this->normalizePath($path2);
+ public function copy($source, $target, $isFile = null) {
+ $source = $this->normalizePath($source);
+ $target = $this->normalizePath($target);
- if ($isFile === true || $this->is_file($path1)) {
+ if ($isFile === true || $this->is_file($source)) {
try {
$this->getConnection()->copyObject([
'Bucket' => $this->bucket,
- 'Key' => $this->cleanKey($path2),
- 'CopySource' => S3Client::encodeKey($this->bucket . '/' . $path1)
+ 'Key' => $this->cleanKey($target),
+ 'CopySource' => S3Client::encodeKey($this->bucket . '/' . $source)
]);
$this->testTimeout();
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
} else {
- $this->remove($path2);
+ $this->remove($target);
try {
- $this->mkdir($path2);
+ $this->mkdir($target);
$this->testTimeout();
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
- foreach ($this->getDirectoryContent($path1) as $item) {
- $source = $path1 . '/' . $item['name'];
- $target = $path2 . '/' . $item['name'];
+ foreach ($this->getDirectoryContent($source) as $item) {
+ $source = $source . '/' . $item['name'];
+ $target = $target . '/' . $item['name'];
$this->copy($source, $target, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER);
}
}
- $this->invalidateCache($path2);
+ $this->invalidateCache($target);
return true;
}
- public function rename($path1, $path2) {
- $path1 = $this->normalizePath($path1);
- $path2 = $this->normalizePath($path2);
+ public function rename($source, $target) {
+ $source = $this->normalizePath($source);
+ $target = $this->normalizePath($target);
- if ($this->is_file($path1)) {
- if ($this->copy($path1, $path2) === false) {
+ if ($this->is_file($source)) {
+ if ($this->copy($source, $target) === false) {
return false;
}
- if ($this->unlink($path1) === false) {
- $this->unlink($path2);
+ if ($this->unlink($source) === false) {
+ $this->unlink($target);
return false;
}
} else {
- if ($this->copy($path1, $path2) === false) {
+ if ($this->copy($source, $target) === false) {
return false;
}
- if ($this->rmdir($path1) === false) {
- $this->rmdir($path2);
+ if ($this->rmdir($source) === false) {
+ $this->rmdir($target);
return false;
}
}
@@ -642,7 +666,10 @@ class AmazonS3 extends \OC\Files\Storage\Common {
unlink($tmpFile);
return true;
} catch (S3Exception $e) {
- \OC::$server->getLogger()->logException($e, ['app' => 'files_external']);
+ $this->logger->error($e->getMessage(), [
+ 'app' => 'files_external',
+ 'exception' => $e,
+ ]);
return false;
}
}
diff --git a/apps/files_external/lib/Lib/Storage/FTP.php b/apps/files_external/lib/Lib/Storage/FTP.php
index d424ffe3cdd..0350035a11a 100644
--- a/apps/files_external/lib/Lib/Storage/FTP.php
+++ b/apps/files_external/lib/Lib/Storage/FTP.php
@@ -333,9 +333,9 @@ class FTP extends Common {
}
}
- public function rename($path1, $path2) {
- $this->unlink($path2);
- return $this->getConnection()->rename($this->buildPath($path1), $this->buildPath($path2));
+ public function rename($source, $target) {
+ $this->unlink($target);
+ return $this->getConnection()->rename($this->buildPath($source), $this->buildPath($target));
}
public function getDirectoryContent($directory): \Traversable {
diff --git a/apps/files_external/lib/Lib/Storage/FtpConnection.php b/apps/files_external/lib/Lib/Storage/FtpConnection.php
index bc4be18e42e..c6f9a5c91b0 100644
--- a/apps/files_external/lib/Lib/Storage/FtpConnection.php
+++ b/apps/files_external/lib/Lib/Storage/FtpConnection.php
@@ -85,8 +85,8 @@ class FtpConnection {
return @ftp_rmdir($this->connection, $path);
}
- public function rename(string $path1, string $path2) {
- return @ftp_rename($this->connection, $path1, $path2);
+ public function rename(string $source, string $target) {
+ return @ftp_rename($this->connection, $source, $target);
}
public function mdtm(string $path) {
diff --git a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php
index 06ede120f5a..680a51cfa10 100644
--- a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php
+++ b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php
@@ -36,7 +36,7 @@ class SFTPReadStream implements File {
/** @var \phpseclib\Net\SFTP */
private $sftp;
- /** @var resource */
+ /** @var string */
private $handle;
/** @var int */
@@ -61,7 +61,6 @@ class SFTPReadStream implements File {
* Load the source from the stream context and return the context options
*
* @param string $name
- * @return array
* @throws \BadMethodCallException
*/
protected function loadContext($name) {
@@ -202,5 +201,6 @@ class SFTPReadStream implements File {
if (!$this->sftp->_close_handle($this->handle)) {
return false;
}
+ return true;
}
}
diff --git a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
index b1518809f09..6682a49d8f6 100644
--- a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
+++ b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php
@@ -36,7 +36,7 @@ class SFTPWriteStream implements File {
/** @var \phpseclib\Net\SFTP */
private $sftp;
- /** @var resource */
+ /** @var string */
private $handle;
/** @var int */
@@ -61,7 +61,6 @@ class SFTPWriteStream implements File {
* Load the source from the stream context and return the context options
*
* @param string $name
- * @return array
* @throws \BadMethodCallException
*/
protected function loadContext($name) {
@@ -180,5 +179,6 @@ class SFTPWriteStream implements File {
if (!$this->sftp->_close_handle($this->handle)) {
return false;
}
+ return true;
}
}
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php
index 6c59263ddd5..1d4cf5a7a2e 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -282,7 +282,7 @@ class SMB extends Common implements INotifyStorage {
}
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while getting folder content']);
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -310,7 +310,7 @@ class SMB extends Common implements INotifyStorage {
* @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) {
+ public function rename($source, $target, $retry = true): bool {
if ($this->isRootDir($source) || $this->isRootDir($target)) {
return false;
}
@@ -322,7 +322,7 @@ class SMB extends Common implements INotifyStorage {
} catch (AlreadyExistsException $e) {
if ($retry) {
$this->remove($target);
- $result = $this->share->rename($absoluteSource, $absoluteTarget, false);
+ $result = $this->share->rename($absoluteSource, $absoluteTarget);
} else {
$this->logger->logException($e, ['level' => ILogger::WARN]);
return false;
@@ -330,7 +330,7 @@ class SMB extends Common implements INotifyStorage {
} catch (InvalidArgumentException $e) {
if ($retry) {
$this->remove($target);
- $result = $this->share->rename($absoluteSource, $absoluteTarget, false);
+ $result = $this->share->rename($absoluteSource, $absoluteTarget);
} else {
$this->logger->logException($e, ['level' => ILogger::WARN]);
return false;
@@ -428,7 +428,7 @@ class SMB extends Common implements INotifyStorage {
return false;
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while deleting file']);
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -515,7 +515,7 @@ class SMB extends Common implements INotifyStorage {
throw new EntityTooLargeException("not enough available space to create file", 0, $e);
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while opening file']);
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -542,7 +542,7 @@ class SMB extends Common implements INotifyStorage {
return false;
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while removing folder']);
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -558,7 +558,7 @@ class SMB extends Common implements INotifyStorage {
throw new EntityTooLargeException("not enough available space to create file", 0, $e);
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while creating file']);
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -655,7 +655,7 @@ class SMB extends Common implements INotifyStorage {
return true;
} catch (ConnectException $e) {
$this->logger->logException($e, ['message' => 'Error while creating folder']);
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
} catch (Exception $e) {
return false;
}
@@ -670,7 +670,7 @@ class SMB extends Common implements INotifyStorage {
} catch (ForbiddenException $e) {
return false;
} catch (ConnectException $e) {
- throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
+ throw new StorageNotAvailableException($e->getMessage(), (int)$e->getCode(), $e);
}
}
diff --git a/apps/files_external/lib/Lib/Storage/StreamWrapper.php b/apps/files_external/lib/Lib/Storage/StreamWrapper.php
index dc203399646..79387e14cf6 100644
--- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php
+++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php
@@ -117,8 +117,8 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common {
return copy($path, $this->constructUrl($target));
}
- public function rename($path1, $path2) {
- return rename($this->constructUrl($path1), $this->constructUrl($path2));
+ public function rename($source, $target) {
+ return rename($this->constructUrl($source), $this->constructUrl($target));
}
public function stat($path) {
diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php
index cc0ee6c7c21..85b3727f4db 100644
--- a/apps/files_external/lib/Lib/Storage/Swift.php
+++ b/apps/files_external/lib/Lib/Storage/Swift.php
@@ -482,25 +482,25 @@ class Swift extends \OC\Files\Storage\Common {
}
}
- public function copy($path1, $path2) {
- $path1 = $this->normalizePath($path1);
- $path2 = $this->normalizePath($path2);
+ public function copy($source, $target) {
+ $source = $this->normalizePath($source);
+ $target = $this->normalizePath($target);
- $fileType = $this->filetype($path1);
+ $fileType = $this->filetype($source);
if ($fileType) {
// make way
- $this->unlink($path2);
+ $this->unlink($target);
}
if ($fileType === 'file') {
try {
- $source = $this->fetchObject($path1);
- $source->copy([
- 'destination' => $this->bucket . '/' . $path2
+ $sourceObject = $this->fetchObject($source);
+ $sourceObject->copy([
+ 'destination' => $this->bucket . '/' . $target
]);
// invalidate target object to force repopulation on fetch
- $this->objectCache->remove($path2);
- $this->objectCache->remove($path2 . '/');
+ $this->objectCache->remove($target);
+ $this->objectCache->remove($target . '/');
} catch (BadResponseError $e) {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
@@ -510,13 +510,13 @@ class Swift extends \OC\Files\Storage\Common {
}
} elseif ($fileType === 'dir') {
try {
- $source = $this->fetchObject($path1 . '/');
- $source->copy([
- 'destination' => $this->bucket . '/' . $path2 . '/'
+ $sourceObject = $this->fetchObject($source . '/');
+ $sourceObject->copy([
+ 'destination' => $this->bucket . '/' . $target . '/'
]);
// invalidate target object to force repopulation on fetch
- $this->objectCache->remove($path2);
- $this->objectCache->remove($path2 . '/');
+ $this->objectCache->remove($target);
+ $this->objectCache->remove($target . '/');
} catch (BadResponseError $e) {
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
'exception' => $e,
@@ -525,14 +525,14 @@ class Swift extends \OC\Files\Storage\Common {
return false;
}
- $dh = $this->opendir($path1);
+ $dh = $this->opendir($source);
while ($file = readdir($dh)) {
if (\OC\Files\Filesystem::isIgnoredDir($file)) {
continue;
}
- $source = $path1 . '/' . $file;
- $target = $path2 . '/' . $file;
+ $source = $source . '/' . $file;
+ $target = $target . '/' . $file;
$this->copy($source, $target);
}
} else {
@@ -543,22 +543,22 @@ class Swift extends \OC\Files\Storage\Common {
return true;
}
- public function rename($path1, $path2) {
- $path1 = $this->normalizePath($path1);
- $path2 = $this->normalizePath($path2);
+ public function rename($source, $target) {
+ $source = $this->normalizePath($source);
+ $target = $this->normalizePath($target);
- $fileType = $this->filetype($path1);
+ $fileType = $this->filetype($source);
if ($fileType === 'dir' || $fileType === 'file') {
// copy
- if ($this->copy($path1, $path2) === false) {
+ if ($this->copy($source, $target) === false) {
return false;
}
// cleanup
- if ($this->unlink($path1) === false) {
+ if ($this->unlink($source) === false) {
throw new \Exception('failed to remove original');
- $this->unlink($path2);
+ $this->unlink($target);
return false;
}
diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php
index 20e5aea62d2..757f9d35bdb 100644
--- a/apps/files_external/lib/Lib/StorageConfig.php
+++ b/apps/files_external/lib/Lib/StorageConfig.php
@@ -126,17 +126,17 @@ class StorageConfig implements \JsonSerializable {
/**
* Creates a storage config
*
- * @param int|null $id config id or null for a new config
+ * @param int|string $id config id or null for a new config
*/
public function __construct($id = null) {
- $this->id = $id;
+ $this->id = $id ?? -1;
$this->mountOptions['enable_sharing'] = false;
}
/**
* Returns the configuration id
*
- * @return int
+ * @retun int
*/
public function getId() {
return $this->id;
@@ -147,7 +147,7 @@ class StorageConfig implements \JsonSerializable {
*
* @param int $id configuration id
*/
- public function setId($id) {
+ public function setId(int $id): void {
$this->id = $id;
}