pynab icon indicating copy to clipboard operation
pynab copied to clipboard

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

Open brookesy2 opened this issue 8 years ago • 2 comments

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.

brookesy2 avatar Jul 18 '16 13:07 brookesy2

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.

gkoh avatar Sep 19 '16 01:09 gkoh

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

brookesy2 avatar Sep 19 '16 18:09 brookesy2