Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error when trying to extract a single file that is not in archive #364

Closed
gluttony38 opened this issue Feb 11, 2019 · 2 comments
Closed
Labels
fixed Issue or bug has been fixed

Comments

@gluttony38
Copy link

Hi,

As we can seen in the sources, in the case of trying to extract a single file that is not in an archive, mz_zip_reader_save_all is supposed to return MZ_END_OF_LIST error:

int32_t minizip_extract(const char *path, const char *pattern, const char *destination, const char *password, minizip_opt *options)
{
[...]
        /* Save all entries in zip file to destination directory */
        err = mz_zip_reader_save_all(reader, destination);

        if (err == MZ_END_OF_LIST && pattern != NULL)
            printf("Files matching %s not found in zip file\n", pattern);
[...]
}

For example with file ZipExample.zip containing a few files:

ZipExample
├── sourceFile.txt
└── subfolder
    ├── empty
    └── nonempty

If I extract an existing file it actually return MZ_OK (0) but it also returns MZ_OK when trying to extract a non-existing file (and we can see that the "file matching not found" log is not printed):

> ./minizip -x ZipExample.zip subfolder/nonempty
Minizip 2.8.3 - https://github.com/nmoinvaz/minizip
---------------------------------------------------
-x ZipExample.zip subfolder/nonempty 
Archive ZipExample.zip
Extracting subfolder/nonempty
> echo $?
0

> ./minizip -x ZipExample.zip sourceFile.txt
Minizip 2.8.3 - https://github.com/nmoinvaz/minizip
---------------------------------------------------
-x ZipExample.zip sourceFile.txt 
Archive ZipExample.zip
Extracting sourceFile.txt
> echo $?
0

> ./minizip -x ZipExample.zip there/is/no/such/file/in/archive
Minizip 2.8.3 - https://github.com/nmoinvaz/minizip
---------------------------------------------------
-x ZipExample.zip there/is/no/such/file/in/archive 
Archive ZipExample.zip
> echo $?
0

I'm using your lib in a C++ project then I got a easy workaround calling boost::filesystem::is_regular_file(destinationFolder / singleFile) after extract of single file but it would be nice to have mz_zip_reader_save_all actually returning proper error in this case.

Thanks.

@nmoinvaz
Copy link
Member

I have just made a commit in the dev branch that should fix your issue. Let me know, thanks.

@gluttony38
Copy link
Author

Works for me, thanks !

@nmoinvaz nmoinvaz added bug fixed Issue or bug has been fixed labels Apr 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Issue or bug has been fixed
Projects
None yet
Development

No branches or pull requests

2 participants