Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

If unrar_path is set incorrectly tmp rar files are not deleted. #286

Open
brookesy2 opened this issue Jul 18, 2016 · 2 comments
Open

If unrar_path is set incorrectly tmp rar files are not deleted. #286

brookesy2 opened this issue Jul 18, 2016 · 2 comments

Comments

@brookesy2
Copy link
Collaborator

Haven't read through the code to get to the bottom of this (db.py/rars.py), but just had a situation where unrar was set incorrectly and my tmp dir filled with rars as they were not getting deleted.

Will investigate when I can.

@gkoh
Copy link
Contributor

gkoh commented Sep 19, 2016

I had a look, this is caused by a missed cleanup in pynab/rars.py::get_rar_info().
The actual rar temp file is written early with this:

       # if we got the requested articles, save them to a temp rar
        t = None
        with tempfile.NamedTemporaryFile('wb', suffix='.rar', delete=False) as t:
            t.write(data.encode('ISO-8859-1'))
            t.flush()

Then a little later we do this:

            unrar_path = config.postprocess.get('unrar_path', '/usr/bin/unrar')
            if not (unrar_path and os.path.isfile(unrar_path) and os.access(unrar_path, os.X_OK)):
                log.error('rar: skipping archive decompression because unrar_path is not set or incorrect')
                log.error(
                    'rar: if the rar is not password protected, but contains an inner archive that is, we will not know')
            else:

Other error paths issue an os.remove(t.name) before returning.

It's probably cleanest to fix this by moving the 'unrar_path' checking all the way to the start of the function and bailing early. There's no point in saving the rar if we have no unrar to process it.

@brookesy2
Copy link
Collaborator Author

Agreed, which is what I did locally. When I get some time I can look to make a PR.

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

No branches or pull requests

2 participants