From 50aa474c841c6c232f67a1855841acbdd483a4a9 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 7 Jun 2022 12:07:38 +0100 Subject: bitbake: fetch/wget: Move files into place atomically (Bitbake rev: 7fc4cffebf5dcc1d050416c0b7f7d58c765c1d69) Signed-off-by: Richard Purdie (cherry picked from commit cd7cce4cf4be5c742d29671169354fe84220b47a) Signed-off-by: Steve Sakoman Signed-off-by: Richard Purdie --- bitbake/lib/bb/fetch2/wget.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'bitbake/lib/bb') diff --git a/bitbake/lib/bb/fetch2/wget.py b/bitbake/lib/bb/fetch2/wget.py index 5676d3fd27..d208f5ee2f 100644 --- a/bitbake/lib/bb/fetch2/wget.py +++ b/bitbake/lib/bb/fetch2/wget.py @@ -91,10 +91,9 @@ class Wget(FetchMethod): fetchcmd = self.basecmd - if 'downloadfilename' in ud.parm: - localpath = os.path.join(d.getVar("DL_DIR"), ud.localfile) - bb.utils.mkdirhier(os.path.dirname(localpath)) - fetchcmd += " -O %s" % shlex.quote(localpath) + localpath = os.path.join(d.getVar("DL_DIR"), ud.localfile) + ".tmp" + bb.utils.mkdirhier(os.path.dirname(localpath)) + fetchcmd += " -O %s" % shlex.quote(localpath) if ud.user and ud.pswd: fetchcmd += " --user=%s --password=%s --auth-no-challenge" % (ud.user, ud.pswd) @@ -108,6 +107,10 @@ class Wget(FetchMethod): self._runwget(ud, d, fetchcmd, 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): -- cgit v1.2.3-54-g00ecf