Skip to content

Commit

Permalink
fix: Update children classes of Common to respect copy signature
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Feb 22, 2024
1 parent 679f1d6 commit 4e44aaa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public function touch($path, $mtime = null) {
return true;
}

public function copy($source, $target, $isFile = null) {
public function copy($source, $target, bool $preserveMtime = false, ?bool $isFile = null): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $source has no provided type

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $target has no provided type
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);

Expand Down Expand Up @@ -607,7 +607,7 @@ public function copy($source, $target, $isFile = null) {
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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ public function writeStream(string $path, $stream, int $size = null): int {
}
}

public function copy($source, $target) {
public function copy($source, $target, bool $preserveMtime = false): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $source has no provided type

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $target has no provided type
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);
Expand Down
10 changes: 8 additions & 2 deletions apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public function touch($path, $mtime = null) {
}
}

public function copy($source, $target) {
public function copy($source, $target, bool $preserveMtime = false): bool {

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $source has no provided type

Check notice

Code scanning / Psalm

MissingParamType Note

Parameter $target has no provided type
$source = $this->normalizePath($source);
$target = $this->normalizePath($target);

Expand All @@ -502,6 +502,12 @@ public function copy($source, $target) {
// 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,
Expand Down Expand Up @@ -534,7 +540,7 @@ public function copy($source, $target) {

$source = $source . '/' . $file;
$target = $target . '/' . $file;
$this->copy($source, $target);
$this->copy($source, $target, $preserveMtime);
}
} else {
//file does not exist
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public function copyFromStorage(
$sourceInternalPath,
$targetInternalPath,
$preserveMtime = false
) {
): bool {
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
/** @var ObjectStoreStorage $sourceStorage */
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
Expand All @@ -614,10 +614,10 @@ public function copyFromStorage(
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Lockdown/Filesystem/NullStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function rename($source, $target) {
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');
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public function getDirectDownload($path) {
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');
}

Expand Down

0 comments on commit 4e44aaa

Please sign in to comment.