Conversation
Codecov Report
@@ Coverage Diff @@
## master #7972 +/- ##
============================================
+ Coverage 51.88% 51.95% +0.06%
- Complexity 25297 25305 +8
============================================
Files 1603 1603
Lines 95060 95081 +21
Branches 1388 1388
============================================
+ Hits 49325 49396 +71
+ Misses 45735 45685 -50
|
lib/private/legacy/files.php
Outdated
| $fileSize = 0; | ||
|
|
||
| if (\OC\Files\Filesystem::is_file($path)) { | ||
| $fileSize = \OC\Files\Filesystem::filesize($path); |
There was a problem hiding this comment.
please use getFileInfo instead
lib/private/legacy/files.php
Outdated
| if (\OC\Files\Filesystem::is_file($path)) { | ||
| $fileSize = \OC\Files\Filesystem::filesize($path); | ||
| } elseif (\OC\Files\Filesystem::is_dir($path)) { | ||
| $files= \OC\Files\Filesystem::getDirectoryContent($path); |
There was a problem hiding this comment.
with getFileInfo you can just get the directory size in one go without the need to recurse
lib/private/legacy/files.php
Outdated
| if ($getType === self::ZIP_FILES) { | ||
| $fileSize = 0; | ||
| foreach ($files as $file) { | ||
| $fileSize += \OC\Files\Filesystem::getFileInfo($dir . '/' . $file)['size']; |
There was a problem hiding this comment.
->size() instead of ['size'] for bonus points
There was a problem hiding this comment.
of course I want bonus points
|
I tried it on macOS again and it still is not possible to extract the zip with the built-in tools. I also checked that the first if clause is used and this is the case. |
|
:S stupid OSX. No clue then |
There was a problem hiding this comment.
This makes possible to open downloaded zip files with KDE Archive KIOSlave (that is, directly in a file explorer or in an Open file dialog) :-D
I have taken a look to the Zip specification and it seems that it is safe to use zip32 for a basic (without compression, volumes nor encryption) zip file when all the following conditions are met (do not quote me on this, though ;-) ):
- No file size is larger than 4 bytes (file size < 4294967296); see 4.4.9 uncompressed size
- The size of all files plus their local headers is not larger than 4 bytes; see 4.4.16 relative offset of local header and 4.4.24 offset of start of central directory with respect to the starting disk number
- The total number of entries (files and directories) in the zip file is not larger than 2 bytes (number of entries < 65536); see 4.4.22 total number of entries in the central dir
- The size of the central directory (similar to the local headers for each file) is not larger than 4 bytes; see 4.4.23 size of the central directory
The first two are already covered in this pull request. The fourth one is mostly covered by the margin between 4x1000^3 and 4x1024^3; if I am not mistaken it is still technically possible to create a zip file from files smaller than 4GB with a central directory larger than 4GiB (which would be broken with zip32), but it should not happen in the real world.
However, it could be good to take into account the third case too (that is, use zip32 only if the size is less than 4GB and the total number of files and directories is less than 65536); it is also an unlikely scenario, yet I guess that this one could enter in the plausible category.
|
@danxuliu thanks for the detailed comment 😄 I agree we should take this all properly into account. That way we can just keep track of all the files/folders/file handles. And do all kind of calculations. Including the number of files and the size. |
|
I have noticed a difference in behaviour from the old code to the new one: if one of the files to be downloaded does not exist, before the zip was downloaded anyway but without that file; now an error is shown to the user. I guess the new behaviour is fine, but I mention it just in case ;-)
I could not wait ;-) so I have addressed my own comment about using zip32 only if the number of files and directories is less than 65536 I have also added integration tests for downloading a zip file. The problem is that the tests for zip32/zip64 boundaries (65535/65536 files) are terribly slow; in my system they take more than two and a half hours... But it is a 8~9-years old machine, so let's see if Drone workers can finish them in a reasonable amount of time; if not they can just be disabled in Drone but kept to be manually run when working on zip related things. Pending issues (for this pull request or future ones ;-) ):
|
|
@danxuliu They fail - maybe rebase to get the latest .drone.yml update as well ;) |
|
@MorrisJobke The integration test fails because I naively used |
533ff1d to
08a785a
Compare
|
As I suspected they take too long to run, so I have disabled those large integration tests in Drone. |
|
@MorrisJobke That is expected; a patch for PHPZipStreamer is needed, but it has not been added yet ;-) |
Problem now is, that his actually breaks the download of multiple files for macOS. Where are those fixes? Could we add them to this PR as well? |
Oops, this pull request should not have been in To review state, sorry :-)
The fixes are here: McNetic/PHPZipStreamer#40 I do not know how @rullzer intended to add them to the server (in this pull request, on a different pull request and then rebase this one on top of it, or other approach). |
|
Rebased on master to include #9101 |
* OSX doesn't handle 64zip that well * Some other implentations don't handle it perfectly either * If the file is belog 4GiB (some overhead) => zip32 * This covers the 99% case I bet Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
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>
The data directory is not necessarily located at "../..". The proper directory is now got by running "php console.php config:system:get datadirectory". Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
"--tags=XXX" limits the features or scenarios to be run to those matching the tag filter expression. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Large scenarios take too long to run, so they would be cancelled before they were finished. Therefore, now they are not even run. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
fixes #7782
In some future work we should really move this to some decent Node based API. All this static stuff is making me cry 😭
Requires: