]> git.gsnw.org Git - raspbmirror.git/commitdiff
Merge github be16cc3 (Handle .new files in the existing-file path)
authorGerman Service Network <support@gsnw.de>
Sun, 4 Sep 2022 09:04:22 +0000 (11:04 +0200)
committerGerman Service Network <support@gsnw.de>
Sun, 4 Sep 2022 09:04:22 +0000 (11:04 +0200)
raspbmirror.py

index 514583b4c3a3ca7876fce489ccbf6500a2e95daa..3c516224a6a064c2c7134f22756f3b24dff91e5c 100644 (file)
@@ -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"