Skip to content
Open
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
13 changes: 5 additions & 8 deletions apps/dav/lib/Connector/Sabre/ZipFolderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ public function handleDownload(Request $request, Response $response): ?bool {
throw new Forbidden($errorMessage);
}

$content = empty($files) ? $folder->getDirectoryListing() : [];
foreach ($files as $path) {
$child = $node->getChild($path);
assert($child instanceof Node);
$content[] = $child->getNode();
}

$archiveName = $folder->getName();
if (count(explode('/', trim($folder->getPath(), '/'), 3)) === 2) {
// this is a download of the root folder
Expand All @@ -169,13 +162,17 @@ public function handleDownload(Request $request, Response $response): ?bool {
$rootPath = dirname($folder->getPath());
}

$streamer = new Streamer($tarRequest, -1, count($content), $this->timezoneFactory);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

$streamer = new Streamer($tarRequest, -1, -1, $this->timezoneFactory);
$streamer->sendHeaders($archiveName);
// For full folder downloads we also add the folder itself to the archive
if (empty($files)) {
$streamer->addEmptyDir($archiveName);
}

$content = empty($files) ? $folder->getDirectoryListing() : array_map(fn (string $path) => $folder->get($path), $files);
foreach ($content as $node) {
assert($node instanceof NcNode);
$this->streamNode($streamer, $node, $rootPath);
}
$streamer->finalize();
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function isUserAgentPreferTar(IRequest $request): bool {
* please migrate to `Streamer::isUserAgentPreferTar()` instead.
* @param int|float $size The size of the files in bytes
* @param int $numberOfFiles The number of files (and directories) that will
* be included in the streamed file
* be included in the streamed file, used to detect if zip32 or zip64 should be used, can be set to -1 to enforce zip64
*/
public function __construct(
IRequest|bool $preferTar,
Expand Down Expand Up @@ -80,7 +80,7 @@ public function __construct(
if ($preferTar) {
// If TAR ball is preferred use it
$this->streamerInstance = new TarStreamer();
} elseif ($size > 0 && $size < 4 * 1000 * 1000 * 1000 && $numberOfFiles < 65536) {
} elseif ($size > 0 && $size < 4 * 1000 * 1000 * 1000 && $numberOfFiles < 65536 && $numberOfFiles >= 0) {
$this->streamerInstance = new ZipStreamer(['zip64' => false]);
} else {
$this->streamerInstance = new ZipStreamer(['zip64' => true]);
Expand Down
Loading