Skip to content

Commit 9e754ca

Browse files
Merge pull request #54412 from nextcloud/backport/54401/stable31
[stable31] fix(ZipFolderPlugin): set mtime of directories in archive
2 parents 8f2db6b + e7cc199 commit 9e754ca

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,16 @@ protected function streamNode(Streamer $streamer, NcNode $node, string $rootPath
6767
// Remove the root path from the filename to make it relative to the requested folder
6868
$filename = str_replace($rootPath, '', $node->getPath());
6969

70+
$mtime = $node->getMTime();
7071
if ($node instanceof NcFile) {
7172
$resource = $node->fopen('rb');
7273
if ($resource === false) {
7374
$this->logger->info('Cannot read file for zip stream', ['filePath' => $node->getPath()]);
7475
throw new \Sabre\DAV\Exception\ServiceUnavailable('Requested file can currently not be accessed.');
7576
}
76-
$streamer->addFileFromStream($resource, $filename, $node->getSize(), $node->getMTime());
77+
$streamer->addFileFromStream($resource, $filename, $node->getSize(), $mtime);
7778
} elseif ($node instanceof NcFolder) {
78-
$streamer->addEmptyDir($filename);
79+
$streamer->addEmptyDir($filename, $mtime);
7980
$content = $node->getDirectoryListing();
8081
foreach ($content as $subNode) {
8182
$this->streamNode($streamer, $subNode, $rootPath);

lib/private/Streamer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,16 @@ public function addFileFromStream($stream, string $internalName, int|float $size
170170
/**
171171
* Add an empty directory entry to the archive.
172172
*
173-
* @param string $dirName Directory Path and name to be added to the archive.
174-
* @return bool $success
173+
* @param $dirName - Directory Path and name to be added to the archive.
174+
* @param $timestamp - Modification time of the directory (defaults to current time)
175175
*/
176-
public function addEmptyDir($dirName) {
177-
return $this->streamerInstance->addEmptyDir($dirName);
176+
public function addEmptyDir(string $dirName, int $timestamp = 0): bool {
177+
$options = null;
178+
if ($timestamp > 0) {
179+
$options = ['timestamp' => $timestamp];
180+
}
181+
182+
return $this->streamerInstance->addEmptyDir($dirName, $options);
178183
}
179184

180185
/**

0 commit comments

Comments
 (0)