tifftools icon indicating copy to clipboard operation
tifftools copied to clipboard

(un)set with --overwrite can do better than shutil.copyfile

Open edswangren opened this issue 7 months ago • 1 comments

It seems to me, anyway.

from commands.py:538 tiff_set

if os.path.realpath(source) == os.path.realpath(output) and source != '-':
    with tempfile.TemporaryDirectory('tifftools') as tmpdir:
        output = os.path.join(tmpdir, 'output.tiff')
        _tiff_set(source, output, setlist, unset, setfrom, **kwargs)
        with open(source, 'r+b') as fdest, open(output, 'rb') as fsrc:
           fdest.truncate(0)
            shutil.copyfileobj(fsrc, fdest)

I lost a file just now sending an interrupt during shutil.copyfileobj. os.replace or even shutil.move are safer and more efficient alternatives.

edswangren avatar Aug 02 '24 00:08 edswangren