Skip to contentSkip to conversation

fetch2/wget: Fix failure path for files that are empty or don't exist

PATCH In review Richard Purdie 2 participants 3 messages May 30, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2/wget: Fix failure path for files that are empty or don't exist

When we intercepted the file download to a temp file, we broke the exist/size checks which need to happen before the rename. Correct the ordering.

For some reason, python 3.12 exposes this problem in the selftests differently to previous versions.

---
 lib/bb/fetch2/wget.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
lib/bb/fetch2/wget.py +7 -7
index fbfa6938ac..3c213370b5 100644
@@ -139,19 +139,19 @@ class Wget(FetchMethod):
         # source, one with an incorrect checksum)
         bb.fetch2.verify_checksum(ud, d, localpath=localpath, fatal_nochecksum=False)
 
-        # Remove the ".tmp" and move the file into position atomically
-        # Our lock prevents multiple writers but mirroring code may grab incomplete files
-        os.rename(localpath, localpath[:-4])
-
         # Sanity check since wget can pretend it succeed when it didn't
         # Also, this used to happen if sourceforge sent us to the mirror page
-        if not os.path.exists(ud.localpath):
+        if not os.path.exists(localpath):
             raise FetchError("The fetch command returned success for url %s but %s doesn't exist?!" % (uri, ud.localpath), uri)
 
-        if os.path.getsize(ud.localpath) == 0:
-            os.remove(ud.localpath)
+        if os.path.getsize(localpath) == 0:
+            os.remove(localpath)
             raise FetchError("The fetch of %s resulted in a zero size file?! Deleting and failing since this isn't right." % (uri), uri)
 
+        # Remove the ".tmp" and move the file into position atomically
+        # Our lock prevents multiple writers but mirroring code may grab incomplete files
+        os.rename(localpath, localpath[:-4])
+
         return True
 
     def checkstatus(self, fetch, ud, d, try_again=True):
#1 lore raw
Quoted 32 lines · Richard Purdie via lists.openembedded.org

When we intercepted the file download to a temp file, we broke the exist/size checks which need to happen before the rename. Correct the ordering.

For some reason, python 3.12 exposes this problem in the selftests differently to previous versions.

---
 lib/bb/fetch2/wget.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
lib/bb/fetch2/wget.py +0 -2
index fbfa6938ac..3c213370b5 100644
@@ -139,19 +139,19 @@ class Wget(FetchMethod):
         # source, one with an incorrect checksum)
         bb.fetch2.verify_checksum(ud, d, localpath=localpath,
 fatal_nochecksum=False)
 
-        # Remove the ".tmp" and move the file into position atomically
-        # Our lock prevents multiple writers but mirroring code may grab

incomplete files

lib/bb/fetch2/wget.py +0 -2
-        os.rename(localpath, localpath[:-4])
-
         # Sanity check since wget can pretend it succeed when it didn't
         # Also, this used to happen if sourceforge sent us to the mirror

page

lib/bb/fetch2/wget.py +1 -1
-        if not os.path.exists(ud.localpath):
+        if not os.path.exists(localpath):
             raise FetchError("The fetch command returned success for url
Quoted 2 lines

%s but %s doesn't exist?!" % (uri, ud.localpath), uri)

Do we also want to change 'ud.localpath' to 'localpath' in the FetchError message?

Quoted 28 lines
lib/bb/fetch2/wget.py +2 -2
-        if os.path.getsize(ud.localpath) == 0:
-            os.remove(ud.localpath)
+        if os.path.getsize(localpath) == 0:
+            os.remove(localpath)
             raise FetchError("The fetch of %s resulted in a zero size

file?! Deleting and failing since this isn't right." % (uri), uri)

lib/bb/fetch2/wget.py +2 -0
+        # Remove the ".tmp" and move the file into position atomically
+        # Our lock prevents multiple writers but mirroring code may grab

incomplete files

lib/bb/fetch2/wget.py +2 -1
+        os.rename(localpath, localpath[:-4])
+
         return True
 
     def checkstatus(self, fetch, ud, d, try_again=True):
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group. View/Reply Online (#16293):
https://lists.openembedded.org/g/bitbake-devel/message/16293
Mute This Topic: https://lists.openembedded.org/mt/106392412/924729
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 11 lines · Tim Orling
Quoted 7 lines · Richard Purdie via lists.openembedded.org

         # Sanity check since wget can pretend it succeed when it didn't
         # Also, this used to happen if sourceforge sent us to the mirror page
-        if not os.path.exists(ud.localpath):
+        if not os.path.exists(localpath):
             raise FetchError("The fetch command returned success for url %s but %s doesn't exist?!" % (uri, ud.localpath), uri)

Do we also want to change 'ud.localpath' to 'localpath' in the FetchError message?

We do, yes. However whilst this fixed things in my local test, the queued commit in master-next didn't work on the f40 worker. Something odd is still going on which we need to get to the bottom of :/.

Cheers,

Richard