Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
susnux committed Aug 14, 2025
commit e7cc19966ef238ebbdf0524ae881572a8860c37e
5 changes: 3 additions & 2 deletions apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Loading