diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-02-06 14:03:50 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-04-06 15:59:30 +0200 |
commit | 90fdf83ca7648418f899e28490f65de53fcd31d1 (patch) | |
tree | 50d98da38954e800576d75e34da47301df891cec /lib/private/legacy/files.php | |
parent | 4a73f645e5a60d8adece72e6c231c2a1be13473d (diff) | |
download | nextcloud-server-90fdf83ca7648418f899e28490f65de53fcd31d1.tar.gz nextcloud-server-90fdf83ca7648418f899e28490f65de53fcd31d1.zip |
Use zip32 only if there are less than 65536 files
A zip32 file can contain, at most, 65535 files (and folders), so take
that constraint into account.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'lib/private/legacy/files.php')
-rw-r--r-- | lib/private/legacy/files.php | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/private/legacy/files.php b/lib/private/legacy/files.php index b7c99b7fef8..9281c1f7da4 100644 --- a/lib/private/legacy/files.php +++ b/lib/private/legacy/files.php @@ -146,17 +146,23 @@ class OC_Files { self::lockFiles($view, $dir, $files); - /* Calculate filesize */ + /* Calculate filesize and number of files */ if ($getType === self::ZIP_FILES) { + $fileInfos = array(); $fileSize = 0; foreach ($files as $file) { - $fileSize += \OC\Files\Filesystem::getFileInfo($dir . '/' . $file)->getSize(); + $fileInfo = \OC\Files\Filesystem::getFileInfo($dir . '/' . $file); + $fileSize += $fileInfo->getSize(); + $fileInfos[] = $fileInfo; } + $numberOfFiles = self::getNumberOfFiles($fileInfos); } elseif ($getType === self::ZIP_DIR) { - $fileSize = \OC\Files\Filesystem::getFileInfo($dir . '/' . $files)->getSize(); + $fileInfo = \OC\Files\Filesystem::getFileInfo($dir . '/' . $files); + $fileSize = $fileInfo->getSize(); + $numberOfFiles = self::getNumberOfFiles(array($fileInfo)); } - $streamer = new Streamer(\OC::$server->getRequest(), $fileSize); + $streamer = new Streamer(\OC::$server->getRequest(), $fileSize, $numberOfFiles); OC_Util::obEnd(); $streamer->sendHeaders($name); @@ -325,6 +331,29 @@ class OC_Files { } /** + * Returns the total (recursive) number of files and folders in the given + * FileInfos. + * + * @param \OCP\Files\FileInfo[] $fileInfos the FileInfos to count + * @return int the total number of files and folders + */ + private static function getNumberOfFiles($fileInfos) { + $numberOfFiles = 0; + + $view = new View(); + + while ($fileInfo = array_pop($fileInfos)) { + $numberOfFiles++; + + if ($fileInfo->getType() === \OCP\Files\FileInfo::TYPE_FOLDER) { + $fileInfos = array_merge($fileInfos, $view->getDirectoryContent($fileInfo->getPath())); + } + } + + return $numberOfFiles; + } + + /** * @param View $view * @param string $dir * @param string[]|string $files |