summaryrefslogtreecommitdiffstats
path: root/lib/bb/fetch2
diff options
context:
space:
mode:
authorSaul Wold <sgw@linux.intel.com>2011-02-07 17:29:46 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-02-10 23:37:14 +0000
commit5f0d6b75a0aa2ca5fc212d9fb34554fcf7486639 (patch)
tree744991ce1ee9eadd838de761bdf360ee3d2fc6ce /lib/bb/fetch2
parentd1a37060cdbf30a2636b8647dfe296736a64da3b (diff)
downloadbitbake-5f0d6b75a0aa2ca5fc212d9fb34554fcf7486639.tar.gz
fetch2: add try/finally to ensure lockfile is unlocked on failure
(From Poky rev: 1544aa8ab4a80d529a001e27b473645f2caec87c) Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/fetch2')
-rw-r--r--lib/bb/fetch2/__init__.py86
1 files changed, 44 insertions, 42 deletions
diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index fcece9d04..bbd7da166 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -830,50 +830,52 @@ class Fetch(object):
lf = bb.utils.lockfile(ud.lockfile)
- if not m.need_update(u, ud, self.d):
- localpath = ud.localpath
- elif m.try_premirror(u, ud, self.d):
- mirrors = mirror_from_string(bb.data.getVar('PREMIRRORS', self.d, True))
- mirrorpath = try_mirrors(self.d, ud, mirrors, False)
- if mirrorpath and os.path.basename(mirrorpath) == os.path.basename(ud.localpath):
- localpath = mirrorpath
- elif mirrorpath and os.path.exists(mirrorpath) and not mirrorpath.startswith(self.d.getVar("DL_DIR", True)):
- os.symlink(mirrorpath, os.path.join(self.d.getVar("DL_DIR", True), os.path.basename(mirrorpath)))
-
- if bb.data.getVar("BB_FETCH_PREMIRRORONLY", self.d, True) is None:
- if not localpath and m.need_update(u, ud, self.d):
+ try:
+ if not m.need_update(u, ud, self.d):
+ localpath = ud.localpath
+ elif m.try_premirror(u, ud, self.d):
+ mirrors = mirror_from_string(bb.data.getVar('PREMIRRORS', self.d, True))
+ mirrorpath = try_mirrors(self.d, ud, mirrors, False)
+ if mirrorpath and os.path.basename(mirrorpath) == os.path.basename(ud.localpath):
+ localpath = mirrorpath
+ elif mirrorpath and os.path.exists(mirrorpath) and not mirrorpath.startswith(self.d.getVar("DL_DIR", True)):
+ os.symlink(mirrorpath, os.path.join(self.d.getVar("DL_DIR", True), os.path.basename(mirrorpath)))
+
+ if bb.data.getVar("BB_FETCH_PREMIRRORONLY", self.d, True) is None:
+ if not localpath and m.need_update(u, ud, self.d):
+ try:
+ m.download(u, ud, self.d)
+ if hasattr(m, "build_mirror_data"):
+ m.build_mirror_data(u, ud, self.d)
+ localpath = ud.localpath
+
+ except BBFetchException:
+ # Remove any incomplete file
+ bb.utils.remove(ud.localpath)
+ mirrors = mirror_from_string(bb.data.getVar('MIRRORS', self.d, True))
+ localpath = try_mirrors (self.d, ud, mirrors)
+
+ if not localpath or not os.path.exists(localpath):
+ raise FetchError("Unable to fetch URL %s from any source." % u, u)
+
+ # The local fetcher can return an alternate path so we symlink
+ if os.path.exists(localpath) and not os.path.exists(ud.localpath):
+ os.symlink(localpath, ud.localpath)
+
+ if os.path.exists(ud.donestamp):
+ # Touch the done stamp file to show active use of the download
try:
- m.download(u, ud, self.d)
- if hasattr(m, "build_mirror_data"):
- m.build_mirror_data(u, ud, self.d)
- localpath = ud.localpath
-
- except BBFetchException:
- # Remove any incomplete file
- bb.utils.remove(ud.localpath)
- mirrors = mirror_from_string(bb.data.getVar('MIRRORS', self.d, True))
- localpath = try_mirrors (self.d, ud, mirrors)
-
- if not localpath or not os.path.exists(localpath):
- raise FetchError("Unable to fetch URL %s from any source." % u, u)
-
- # The local fetcher can return an alternate path so we symlink
- if os.path.exists(localpath) and not os.path.exists(ud.localpath):
- os.symlink(localpath, ud.localpath)
-
- if os.path.exists(ud.donestamp):
- # Touch the done stamp file to show active use of the download
- try:
- os.utime(ud.donestamp, None)
- except:
- # Errors aren't fatal here
- pass
- else:
- # Only check the checksums if we've not seen this item before, then create the stamp
- verify_checksum(u, ud, self.d)
- open(ud.donestamp, 'w').close()
+ os.utime(ud.donestamp, None)
+ except:
+ # Errors aren't fatal here
+ pass
+ else:
+ # Only check the checksums if we've not seen this item before, then create the stamp
+ verify_checksum(u, ud, self.d)
+ open(ud.donestamp, 'w').close()
- bb.utils.unlockfile(lf)
+ finally:
+ bb.utils.unlockfile(lf)
def checkstatus(self, urls = []):
"""