File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments