From 32703d050048097102ac4e8c1a54e73fc55c2713 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 220988caba0ae..f198519b45409 100644 --- a/apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php +++ b/apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php @@ -67,15 +67,16 @@ protected function streamNode(Streamer $streamer, NcNode $node, string $rootPath // 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 de663f66e0d20..e579c42c0d7ff 100644 --- a/lib/private/Streamer.php +++ b/lib/private/Streamer.php @@ -170,11 +170,16 @@ public function addFileFromStream($stream, string $internalName, int|float $size /** * 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); } /**