From 3f0b9e333f618ba638c931f4efa9922e1a504885 Mon Sep 17 00:00:00 2001 From: German Service Network Date: Sun, 19 Jul 2020 11:53:42 +0200 Subject: [PATCH] Merge github 33e5cb9 (When a file to remove points into the temporary directory, only call ensuresafepath on the path relative to the temporary directory.) --- raspbmirror.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/raspbmirror.py b/raspbmirror.py index 7a29631..1575a66 100644 --- a/raspbmirror.py +++ b/raspbmirror.py @@ -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. -- 2.43.0