From d37436a49f2d6f41d537fb13e0b2ae04a45f909d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 22 Feb 2024 11:53:24 +0100 Subject: [PATCH] fix: Update children classes of Common to respect copy signature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/files_external/lib/Lib/Storage/AmazonS3.php | 4 ++-- apps/files_external/lib/Lib/Storage/SFTP.php | 4 ++-- apps/files_external/lib/Lib/Storage/Swift.php | 10 ++++++++-- apps/files_trashbin/tests/StorageTest.php | 2 +- lib/private/Files/ObjectStore/ObjectStoreStorage.php | 6 +++--- lib/private/Files/Storage/DAV.php | 2 +- lib/private/Files/Storage/FailedStorage.php | 4 ++-- lib/private/Lockdown/Filesystem/NullStorage.php | 4 ++-- tests/lib/Files/ViewTest.php | 2 +- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index e5fa98313d5..29e4765f2ac 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -573,7 +573,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function copy($source, $target, $isFile = null) { + public function copy($source, $target, bool $preserveMtime = false, ?bool $isFile = null): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -607,7 +607,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { foreach ($this->getDirectoryContent($source) as $item) { $childSource = $source . '/' . $item['name']; $childTarget = $target . '/' . $item['name']; - $this->copy($childSource, $childTarget, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER); + $this->copy($childSource, $childTarget, $preserveMtime, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER); } } diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index 3fa04209fa0..d779a550d13 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -519,9 +519,9 @@ class SFTP extends Common { } } - public function copy($source, $target) { + public function copy($source, $target, bool $preserveMtime = false): bool { if ($this->is_dir($source) || $this->is_dir($target)) { - return parent::copy($source, $target); + return parent::copy($source, $target, $preserveMtime); } else { $absSource = $this->absPath($source); $absTarget = $this->absPath($target); diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index 7283e5ae7b1..6f2e9f1ee1c 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -483,7 +483,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function copy($source, $target) { + public function copy($source, $target, bool $preserveMtime = false): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -502,6 +502,12 @@ class Swift extends \OC\Files\Storage\Common { // invalidate target object to force repopulation on fetch $this->objectCache->remove($target); $this->objectCache->remove($target . '/'); + if ($preserveMtime) { + $mTime = $this->filemtime($source); + if (is_int($mTime)) { + $this->touch($target, $mTime); + } + } } catch (BadResponseError $e) { \OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [ 'exception' => $e, @@ -534,7 +540,7 @@ class Swift extends \OC\Files\Storage\Common { $source = $source . '/' . $file; $target = $target . '/' . $file; - $this->copy($source, $target); + $this->copy($source, $target, $preserveMtime); } } else { //file does not exist diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index 59bd7e0f5ef..953e78375ce 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -54,7 +54,7 @@ use Psr\Log\LoggerInterface; use Test\Traits\MountProviderTrait; class TemporaryNoCross extends Temporary { - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool { return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 7eb284fc774..7793c02be5c 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -596,7 +596,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil $sourceInternalPath, $targetInternalPath, $preserveMtime = false - ) { + ): bool { if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) { /** @var ObjectStoreStorage $sourceStorage */ if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) { @@ -614,10 +614,10 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } - return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } - public function copy($source, $target) { + public function copy($source, $target, bool $preserveMtime = false): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index e5bbbb560da..ffaa70b9fc0 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -565,7 +565,7 @@ class DAV extends Common { } /** {@inheritdoc} */ - public function copy($source, $target) { + public function copy($source, $target, bool $preserveMtime = false): bool { $this->init(); $source = $this->cleanPath($source); $target = $this->cleanPath($target); diff --git a/lib/private/Files/Storage/FailedStorage.php b/lib/private/Files/Storage/FailedStorage.php index 07b3b21d965..9e65d6b5f43 100644 --- a/lib/private/Files/Storage/FailedStorage.php +++ b/lib/private/Files/Storage/FailedStorage.php @@ -132,7 +132,7 @@ class FailedStorage extends Common { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function copy($source, $target) { + public function copy($source, $target, bool $preserveMtime = false): bool { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } @@ -180,7 +180,7 @@ class FailedStorage extends Common { return true; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } diff --git a/lib/private/Lockdown/Filesystem/NullStorage.php b/lib/private/Lockdown/Filesystem/NullStorage.php index a3976733b1a..2dcd4bb81cb 100644 --- a/lib/private/Lockdown/Filesystem/NullStorage.php +++ b/lib/private/Lockdown/Filesystem/NullStorage.php @@ -117,7 +117,7 @@ class NullStorage extends Common { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function copy($source, $target) { + public function copy($source, $target, bool $preserveMtime = false): bool { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } @@ -161,7 +161,7 @@ class NullStorage extends Common { return false; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index b9dd49d71fe..3050a8f14b0 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -39,7 +39,7 @@ class TemporaryNoTouch extends Temporary { } class TemporaryNoCross extends Temporary { - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool { return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); }