fix: Update children classes of Common to respect copy signature

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2024-02-22 11:53:24 +01:00
parent f9b4cf417a
commit d37436a49f
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
9 changed files with 22 additions and 16 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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');
}

View file

@ -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);
}