From: German Service Network Date: Sun, 4 Sep 2022 09:04:22 +0000 (+0200) Subject: Merge github be16cc3 (Handle .new files in the existing-file path) X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3670678af0f28ddc60b9e4030b04073bbc3f0040;p=raspbmirror.git Merge github be16cc3 (Handle .new files in the existing-file path) --- diff --git a/raspbmirror.py b/raspbmirror.py index 514583b..3c51622 100644 --- a/raspbmirror.py +++ b/raspbmirror.py @@ -141,7 +141,8 @@ def getfile(path,sha256,size): sys.exit(1) if len(os.path.dirname(path)) > 0: os.makedirs(os.path.dirname(path),exist_ok=True) - if os.path.isfile(makenewpath(path)): # "new" file already exists, lets check the hash + havenewfile = os.path.isfile(makenewpath(path)) + if havenewfile: # "new" file already exists, lets check the hash fn = makenewpath(path) sha256hashed, tl = getfilesha256andsize(fn) if (sha256 == sha256hashed) and (size == tl): @@ -150,7 +151,7 @@ def getfile(path,sha256,size): return # no download needed but rename is if os.path.isfile(path): # file already exists if (size == os.path.getsize(path)): #no point reading the data and calculating a hash if the size does not match - if (not args.repair) and (path in oldknownfiles): + if (not args.repair) and (path in oldknownfiles) and (not havenewfile): #shortcut exit if file is unchanged, we skip this if a "new" file was detected because #that means some sort of update was going on to the file and may need to be finished/cleaned up. oldsha256,oldsize,oldstatus = oldknownfiles[path] @@ -159,7 +160,7 @@ def getfile(path,sha256,size): sha256hashed, tl = getfilesha256andsize(path) if (sha256 == sha256hashed) and (size == tl): logging.info('existing file '+path.decode('ascii')+' matched by hash and size') - if os.path.isfile(makenewpath(path)): + if havenewfile: #if file is up to date but a "new" file exists and is bad #(we wouldn't have got this far if it was good) #schedule the "new" file for removal by adding it to "basefiles"