Skip to content

Commit d317f45

Browse files
committed
fix(AmazonS3#getMetaData): override getMetaData to preserve directory storage_mtime
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent a0ed68f commit d317f45

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,26 @@ public function stat(string $path): array|false {
336336
return $stat;
337337
}
338338

339+
#[\Override]
340+
public function getMetaData(string $path): ?array {
341+
$data = parent::getMetaData($path);
342+
if ($data !== null && $data['mimetype'] === FileInfo::MIMETYPE_FOLDER) {
343+
// Common::getMetaData sets storage_mtime = mtime, but for S3 virtual directories
344+
// mtime may have been updated by mtime propagation while storage_mtime should
345+
// reflect the actual last storage change. Without this override the scanner sees
346+
// data['storage_mtime'] != cacheData['storage_mtime'] and re-writes the cache,
347+
// causing View::getCacheEntry to trigger propagateChange on every read.
348+
$path = $this->normalizePath($path);
349+
$cacheEntry = $this->getCache()->get($this->getCachePath($path));
350+
if ($cacheEntry instanceof CacheEntry) {
351+
$data['storage_mtime'] = $cacheEntry->getStorageMTime();
352+
} elseif (!$this->isRoot($path) && $directoryMarker = $this->headObject($path . '/')) {
353+
$data['storage_mtime'] = strtotime($directoryMarker['LastModified']);
354+
}
355+
}
356+
return $data;
357+
}
358+
339359
#[\Override]
340360
public function is_dir(string $path): bool {
341361
$path = $this->normalizePath($path);

0 commit comments

Comments
 (0)