From e7cc19966ef238ebbdf0524ae881572a8860c37e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 13 Aug 2025 10:23:47 +0200 Subject: [PATCH] fix(ZipFolderPlugin): set mtime of directories in archive Directories should also have the correct mtime set and not the current time. For this the `Streamer` class needs to support passing a time attribute for creating folders, the underlying library already supports this. Signed-off-by: Ferdinand Thiessen --- apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php | 5 +++-- lib/private/Streamer.php | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php b/apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php index 220988caba0..f198519b454 100644 --- a/apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php @@ -67,15 +67,16 @@ class ZipFolderPlugin extends ServerPlugin { // Remove the root path from the filename to make it relative to the requested folder $filename = str_replace($rootPath, '', $node->getPath()); + $mtime = $node->getMTime(); if ($node instanceof NcFile) { $resource = $node->fopen('rb'); if ($resource === false) { $this->logger->info('Cannot read file for zip stream', ['filePath' => $node->getPath()]); throw new \Sabre\DAV\Exception\ServiceUnavailable('Requested file can currently not be accessed.'); } - $streamer->addFileFromStream($resource, $filename, $node->getSize(), $node->getMTime()); + $streamer->addFileFromStream($resource, $filename, $node->getSize(), $mtime); } elseif ($node instanceof NcFolder) { - $streamer->addEmptyDir($filename); + $streamer->addEmptyDir($filename, $mtime); $content = $node->getDirectoryListing(); foreach ($content as $subNode) { $this->streamNode($streamer, $subNode, $rootPath); diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php index de663f66e0d..e579c42c0d7 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -170,11 +170,16 @@ class Streamer { /** * Add an empty directory entry to the archive. * - * @param string $dirName Directory Path and name to be added to the archive. - * @return bool $success + * @param $dirName - Directory Path and name to be added to the archive. + * @param $timestamp - Modification time of the directory (defaults to current time) */ - public function addEmptyDir($dirName) { - return $this->streamerInstance->addEmptyDir($dirName); + public function addEmptyDir(string $dirName, int $timestamp = 0): bool { + $options = null; + if ($timestamp > 0) { + $options = ['timestamp' => $timestamp]; + } + + return $this->streamerInstance->addEmptyDir($dirName, $options); } /**