Skip to content

Commit d37436a

Browse files
committed
fix: Update children classes of Common to respect copy signature
Signed-off-by: Côme Chilliet <[email protected]>
1 parent f9b4cf4 commit d37436a

9 files changed

Lines changed: 22 additions & 16 deletions

File tree

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ public function touch($path, $mtime = null) {
573573
return true;
574574
}
575575

576-
public function copy($source, $target, $isFile = null) {
576+
public function copy($source, $target, bool $preserveMtime = false, ?bool $isFile = null): bool {
577577
$source = $this->normalizePath($source);
578578
$target = $this->normalizePath($target);
579579

@@ -607,7 +607,7 @@ public function copy($source, $target, $isFile = null) {
607607
foreach ($this->getDirectoryContent($source) as $item) {
608608
$childSource = $source . '/' . $item['name'];
609609
$childTarget = $target . '/' . $item['name'];
610-
$this->copy($childSource, $childTarget, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER);
610+
$this->copy($childSource, $childTarget, $preserveMtime, $item['mimetype'] !== FileInfo::MIMETYPE_FOLDER);
611611
}
612612
}
613613

apps/files_external/lib/Lib/Storage/SFTP.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,9 @@ public function writeStream(string $path, $stream, int $size = null): int {
519519
}
520520
}
521521

522-
public function copy($source, $target) {
522+
public function copy($source, $target, bool $preserveMtime = false): bool {
523523
if ($this->is_dir($source) || $this->is_dir($target)) {
524-
return parent::copy($source, $target);
524+
return parent::copy($source, $target, $preserveMtime);
525525
} else {
526526
$absSource = $this->absPath($source);
527527
$absTarget = $this->absPath($target);

apps/files_external/lib/Lib/Storage/Swift.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public function touch($path, $mtime = null) {
483483
}
484484
}
485485

486-
public function copy($source, $target) {
486+
public function copy($source, $target, bool $preserveMtime = false): bool {
487487
$source = $this->normalizePath($source);
488488
$target = $this->normalizePath($target);
489489

@@ -502,6 +502,12 @@ public function copy($source, $target) {
502502
// invalidate target object to force repopulation on fetch
503503
$this->objectCache->remove($target);
504504
$this->objectCache->remove($target . '/');
505+
if ($preserveMtime) {
506+
$mTime = $this->filemtime($source);
507+
if (is_int($mTime)) {
508+
$this->touch($target, $mTime);
509+
}
510+
}
505511
} catch (BadResponseError $e) {
506512
\OC::$server->get(LoggerInterface::class)->error($e->getMessage(), [
507513
'exception' => $e,
@@ -534,7 +540,7 @@ public function copy($source, $target) {
534540

535541
$source = $source . '/' . $file;
536542
$target = $target . '/' . $file;
537-
$this->copy($source, $target);
543+
$this->copy($source, $target, $preserveMtime);
538544
}
539545
} else {
540546
//file does not exist

apps/files_trashbin/tests/StorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
use Test\Traits\MountProviderTrait;
5555

5656
class TemporaryNoCross extends Temporary {
57-
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) {
57+
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool {
5858
return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime);
5959
}
6060

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public function copyFromStorage(
596596
$sourceInternalPath,
597597
$targetInternalPath,
598598
$preserveMtime = false
599-
) {
599+
): bool {
600600
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
601601
/** @var ObjectStoreStorage $sourceStorage */
602602
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
@@ -614,10 +614,10 @@ public function copyFromStorage(
614614
}
615615
}
616616

617-
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath);
617+
return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime);
618618
}
619619

620-
public function copy($source, $target) {
620+
public function copy($source, $target, bool $preserveMtime = false): bool {
621621
$source = $this->normalizePath($source);
622622
$target = $this->normalizePath($target);
623623

lib/private/Files/Storage/DAV.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public function rename($source, $target) {
565565
}
566566

567567
/** {@inheritdoc} */
568-
public function copy($source, $target) {
568+
public function copy($source, $target, bool $preserveMtime = false): bool {
569569
$this->init();
570570
$source = $this->cleanPath($source);
571571
$target = $this->cleanPath($target);

lib/private/Files/Storage/FailedStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function rename($source, $target) {
132132
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
133133
}
134134

135-
public function copy($source, $target) {
135+
public function copy($source, $target, bool $preserveMtime = false): bool {
136136
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
137137
}
138138

@@ -180,7 +180,7 @@ public function verifyPath($path, $fileName) {
180180
return true;
181181
}
182182

183-
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
183+
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool {
184184
throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
185185
}
186186

lib/private/Lockdown/Filesystem/NullStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function rename($source, $target) {
117117
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
118118
}
119119

120-
public function copy($source, $target) {
120+
public function copy($source, $target, bool $preserveMtime = false): bool {
121121
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
122122
}
123123

@@ -161,7 +161,7 @@ public function getDirectDownload($path) {
161161
return false;
162162
}
163163

164-
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
164+
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool {
165165
throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
166166
}
167167

tests/lib/Files/ViewTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function touch($path, $mtime = null) {
3939
}
4040

4141
class TemporaryNoCross extends Temporary {
42-
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) {
42+
public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, bool $preserveMtime = false): bool {
4343
return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime);
4444
}
4545

0 commit comments

Comments
 (0)