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

Detect valid archives #96

Open
arlininger opened this issue Nov 21, 2019 · 3 comments
Open

Detect valid archives #96

arlininger opened this issue Nov 21, 2019 · 3 comments

Comments

@arlininger
Copy link

I'm in the process of migrating from python2 using python-libarchive to python3 using python-libarchive-c. In all, the process has been quite easy (and many thanks to you folks for keeping a similar interface). However, I have run in to a bit of a snag.

I've been detecting whether or not a file is a legitimate archive based on trying to open it and detect errors. This works well for most files, but has been failing when I feed it something that looks like a /etc/passwd file. Previously, when libarchive returns Missing type keyword in mtree specification, the old python-libarchive would raise a ValueError. Now, this simply produces a Warning to the logger and the process continues.

Is there an easy way to make this produce an error that I can catch or otherwise detect invalid archives?

@Changaco
Copy link
Owner

You should be able to intercept the warning message and turn it into an exception by modifying the libarchive.ffi.logger object. The simplest way to do that is probably to replace the logger's warning method. A cleaner solution could be to create a special Handler and call logger.addHandler(handler).

@arlininger
Copy link
Author

Thanks, that got me going in the right direction.

@Changaco
Copy link
Owner

Let's keep this issue open as a feature request. We could add a function named check_archive or is_valid_archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants