Skip to content

Commit 2c9f595

Browse files
Merge pull request #53251 from nextcloud/backport/52242/stable29
[stable29] fix(S3): Use original folder size during copy
2 parents dbe76fe + 077f654 commit 2c9f595

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function __construct($params) {
8888
$this->logger = \OCP\Server::get(LoggerInterface::class);
8989
}
9090

91-
public function mkdir($path, bool $force = false) {
91+
public function mkdir($path, bool $force = false, array $metadata = []) {
9292
$path = $this->normalizePath($path);
9393
if (!$force && $this->file_exists($path)) {
9494
$this->logger->warning("Tried to create an object store folder that already exists: $path");
@@ -98,7 +98,7 @@ public function mkdir($path, bool $force = false) {
9898
$mTime = time();
9999
$data = [
100100
'mimetype' => 'httpd/unix-directory',
101-
'size' => 0,
101+
'size' => $metadata['size'] ?? 0,
102102
'mtime' => $mTime,
103103
'storage_mtime' => $mTime,
104104
'permissions' => \OCP\Constants::PERMISSION_ALL,
@@ -731,7 +731,7 @@ private function copyInner(ICache $sourceCache, ICacheEntry $sourceEntry, string
731731
if ($cache->inCache($to)) {
732732
$cache->remove($to);
733733
}
734-
$this->mkdir($to);
734+
$this->mkdir($to, false, ['size' => $sourceEntry->getSize()]);
735735

736736
foreach ($sourceCache->getFolderContentsById($sourceEntry->getId()) as $child) {
737737
$this->copyInner($sourceCache, $child, $to . '/' . $child->getName());

tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,17 @@ public function testCopyGrantsPermissions() {
275275
$this->assertTrue($cache->inCache('new.txt'));
276276
$this->assertEquals(\OCP\Constants::PERMISSION_ALL, $instance->getPermissions('new.txt'));
277277
}
278+
279+
public function testCopyFolderSize(): void {
280+
$cache = $this->instance->getCache();
281+
282+
$this->instance->mkdir('source');
283+
$this->instance->file_put_contents('source/test.txt', 'foo');
284+
$this->instance->getUpdater()->update('source/test.txt');
285+
$this->assertEquals(3, $cache->get('source')->getSize());
286+
287+
$this->assertTrue($this->instance->copy('source', 'target'));
288+
289+
$this->assertEquals(3, $cache->get('target')->getSize());
290+
}
278291
}

0 commit comments

Comments
 (0)