summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Lib/Storage
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Lib/Storage')
-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
8 files changed, 114 insertions, 87 deletions
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;
}