Zip extraction with top level file fails
fabiante opened this issue · comments
Hi,
I have an update package that looks like this:
UPDATE.md
logs/
test.txt
The extraction of UPDATE.md fails with this exception:
ZipArchive::extractTo(/var/www/html/mysecretapp/UPDATE.md/UPDATE.md): failed to open stream: No such file or directory
Strange thing is that, when debugging, like the extraction should actually work (sorry for the blurring, it all says the same very secret application name 😉):
I don't really get why the path is duplicated.
Edit: Oh, and the foldername
is /var/www/html/mysecretapp/.
When I remove UPDATE.md
and add some file one folder below that, it works. So this zip would be fine:
logs/
test.txt
I don't really get why the path is duplicated.
Yeah the code is wrong and the filename is provided twice. The signature is public ZipArchive::extractTo(string $pathto, array|string|null $files = null): bool
.
Can you try again e.g. with:
if ($zip->extractTo($foldername, $fileStats['name']) === false) {
or
if ($zip->extractTo(dirname($absoluteFilename), $fileStats['name']) === false) {
FYI: The library is not really production-ready, and as the readme says, is more of a proof of concept. But it may work nevertheless ;) The problem here was that I switched to the new zip classes to make it PHP 8 compatible without really testing the changes.
No worries. I think the library is still a good base to work with. I am actually pretty happy that I didn't have to write a lot of the file handling. Similar to #52 there are a couple of things that could be improved IMO like the options to configure a custom download mechanism and a custom index file (update.json) parser. If my integration works out you can expect to get a couple of more PRs / ideas 😉
I will try your suggestion next week, thanks in advance.
Hello,
I've been using your PHP Auto Update library in production for a while now (just updated to the latest 1.0.1) and thanks for this great script, in my case it's prefectly ready for production, except the same zip issue.
I solved it with this replacement:
// in vendor\visualappeal\php-auto-update\src\AutoUpdate.php L.825
if ($zip->extractTo($this->installDir, $fileStats['name']) === false) {