Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use Nodes API for zip streaming
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Dec 19, 2019
commit 79eae96f45dbc953b5bc5512c82f4747c5b69c09
47 changes: 30 additions & 17 deletions lib/private/Streamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@

namespace OC;

use OC\Files\Filesystem;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\InvalidPathException;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\IRequest;
use ownCloud\TarStreamer\TarStreamer;
use ZipStreamer\ZipStreamer;
Expand Down Expand Up @@ -77,23 +83,25 @@ public function __construct(IRequest $request, int $size, int $numberOfFiles){
$this->streamerInstance = new ZipStreamer(['zip64' => PHP_INT_SIZE !== 4]);
}
}

/**
* Send HTTP headers
* @param string $name
* @param string $name
*/
public function sendHeaders($name){
$extension = $this->streamerInstance instanceof ZipStreamer ? '.zip' : '.tar';
$fullName = $name . $extension;
$this->streamerInstance->sendHeaders($fullName);
}

/**
* Stream directory recursively
* @param string $dir
* @param string $internalDir
*
* @throws NotFoundException
* @throws NotPermittedException
* @throws InvalidPathException
*/
public function addDirRecursive($dir, $internalDir='') {
public function addDirRecursive(string $dir, string $internalDir = ''): void {
Copy link
Member

Choose a reason for hiding this comment

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

passing the Node/FileInfo instead of the path here would be nice as it would cut the number of filecache queries in half

Copy link
Member Author

Choose a reason for hiding this comment

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

Passing the Node would be more helpful, I agree and had the same thought. I discarded it to have a simpler and smaller changeset to backport.

$dirname = basename($dir);
$rootDir = $internalDir . $dirname;
if (!empty($rootDir)) {
Expand All @@ -103,22 +111,27 @@ public function addDirRecursive($dir, $internalDir='') {
// prevent absolute dirs
$internalDir = ltrim($internalDir, '/');

$files= \OC\Files\Filesystem::getDirectoryContent($dir);
$userFolder = \OC::$server->getRootFolder()->get(Filesystem::getRoot());
/** @var Folder $dirNode */
$dirNode = $userFolder->get($rootDir);
$files = $dirNode->getDirectoryListing();

foreach($files as $file) {
$filename = $file['name'];
$file = $dir . '/' . $filename;
if(\OC\Files\Filesystem::is_file($file)) {
$filesize = \OC\Files\Filesystem::filesize($file);
$fileTime = \OC\Files\Filesystem::filemtime($file);
$fh = \OC\Files\Filesystem::fopen($file, 'r');
$this->addFileFromStream($fh, $internalDir . $filename, $filesize, $fileTime);
if($file instanceof File) {
$fh = $file->fopen('r');
$this->addFileFromStream(
$fh,
$internalDir . $file->getName(),
$file->getSize(),
$file->getMTime()
);
fclose($fh);
}elseif(\OC\Files\Filesystem::is_dir($file)) {
$this->addDirRecursive($file, $internalDir);
} elseif ($file instanceof Folder) {
$this->addDirRecursive($file->getName(), $internalDir);
}
}
}

/**
* Add a file to the archive at the specified location and file name.
*
Expand Down