fetch2/wget: Fix failure path for files that are empty or don't exist
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
@@ -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):
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.
Signed-off-by Richard Purdie <[email protected]>--- lib/bb/fetch2/wget.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)lib/bb/fetch2/wget.py +0
-2@@ -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 grabincomplete 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 mirrorpage
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 sizefile?! 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 grabincomplete 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]]
-=-=-=-=-=-=-=-=-=-=-=-
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 notos.path.exists(ud.localpath):
+ if notos.path.exists(localpath):
raiseFetchError("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