Skip to content

Commit aa9e8ab

Browse files
committed
fixup!: try to handle uncached folders
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent d6735de commit aa9e8ab

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,15 @@ private function getDirectoryMetaData(string $path): ?array {
672672
if ($cacheEntry instanceof CacheEntry) {
673673
return $cacheEntry->getData();
674674
} else {
675+
$directoryMarker = $path === '.' ? false : $this->headObject($path . '/');
676+
if ($directoryMarker !== false) {
677+
$data = $this->objectToMetaData($directoryMarker);
678+
$data['mimetype'] = FileInfo::MIMETYPE_FOLDER;
679+
$data['permissions'] = Constants::PERMISSION_ALL;
680+
$data['size'] = -1;
681+
return $data;
682+
}
683+
675684
return [
676685
'name' => basename($path),
677686
'mimetype' => FileInfo::MIMETYPE_FOLDER,

apps/files_external/tests/Storage/Amazons3Test.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,31 @@ public function testStatRootPreservesStorageMtimeFromCache(): void {
6464
);
6565
}
6666

67+
/**
68+
* Regression test for uncached S3 folders with a real directory marker object.
69+
*
70+
* mkdir() creates a `<path>/` object in S3. Before the fix, getDirectoryMetaData()
71+
* ignored that marker on a cache miss and returned time(), so simply reading the
72+
* folder could stamp it as "few seconds ago". stat() must use the marker metadata
73+
* instead, which stays stable across repeated reads.
74+
*/
75+
public function testStatDirectoryMarkerPreservesStorageMtimeWithoutCache(): void {
76+
$this->instance->mkdir('markerdir');
77+
78+
$firstStat = $this->instance->stat('markerdir');
79+
$this->assertNotFalse($firstStat);
80+
81+
sleep(2);
82+
83+
$secondStat = $this->instance->stat('markerdir');
84+
$this->assertNotFalse($secondStat);
85+
$this->assertEquals(
86+
$firstStat['storage_mtime'],
87+
$secondStat['storage_mtime'],
88+
'stat() for an uncached S3 directory marker must not synthesize a fresh timestamp on every read'
89+
);
90+
}
91+
6792
/**
6893
* Regression test for Common::getMetaData discarding storage_mtime for S3 directories.
6994
*

0 commit comments

Comments
 (0)