jamesmeneghello / pynab

Newznab-compliant Usenet Indexer written in Python, using PostgreSQL/MySQL-like.
Other
209 stars 44 forks source link

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

Open brookesy2 opened 8 years ago

brookesy2 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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