]> git.gsnw.org Git - raspbmirror.git/commitdiff
Merge github 33e5cb9 (When a file to remove points into the temporary directory,...
authorGerman Service Network <support@gsnw.de>
Sun, 19 Jul 2020 09:53:42 +0000 (11:53 +0200)
committerGerman Service Network <support@gsnw.de>
Sun, 19 Jul 2020 09:53:42 +0000 (11:53 +0200)
raspbmirror.py

index 7a296311fb67a13aaa61685b04eddf7be38802a3..1575a666fe1a9a1c609acb1cdb36336aa79cf8ed 100644 (file)
@@ -661,12 +661,24 @@ def isemptydir(dirpath):
        #return os.path.isdir(dirpath) and ((next(os.scandir(dirpath), None)) is None)
        return os.path.isdir(dirpath) and (len(os.listdir(dirpath)) == 0)
 
+if args.tmpdir is None:
+       tmpdir = None
+else:
+       tmpdir = args.tmpdir.encode('ascii')
+       if tmpdir[-1] != b'/':
+               tmpdir += b'/'
+
 for filepath in removedfiles:
        #file may not actually exist, either due to earlier updates gone-wrong
        #or due to the file being a non-realised uncompressed version of
        #a gzipped file.
        if os.path.exists(filepath):
-               ensuresafepath(filepath)
+               checkpath = filepath
+               #if the path points into the temporary directory we only check the part of it
+               #that is relative to the tempory directory.
+               if tmpdir is not None and filepath.startswith(tmpdir):
+                       checkpath = filepath[len(tmpdir):]
+               ensuresafepath(checkpath)
                logging.info('removing '+filepath.decode('ascii'))
                os.remove(filepath)
                #clean up empty directories.