diff options
author | Saul Wold <sgw@linux.intel.com> | 2011-02-07 17:29:46 -0800 |
---|---|---|
committer | Saul Wold <sgw@linux.intel.com> | 2011-02-07 17:29:46 -0800 |
commit | 1544aa8ab4a80d529a001e27b473645f2caec87c (patch) | |
tree | 398d96fb6e12f4d97bfac8368b1d957005dd1d03 /bitbake | |
parent | 232b6f3c92928c333ad1201aa8eb3706e7251cdf (diff) | |
download | poky-1544aa8ab4a80d529a001e27b473645f2caec87c.tar.gz |
fetch2: add try/finally to ensure lockfile is unlocked on failure
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index fcece9d04b..bbd7da1662 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
@@ -830,50 +830,52 @@ class Fetch(object): | |||
830 | 830 | ||
831 | lf = bb.utils.lockfile(ud.lockfile) | 831 | lf = bb.utils.lockfile(ud.lockfile) |
832 | 832 | ||
833 | if not m.need_update(u, ud, self.d): | 833 | try: |
834 | localpath = ud.localpath | 834 | if not m.need_update(u, ud, self.d): |
835 | elif m.try_premirror(u, ud, self.d): | 835 | localpath = ud.localpath |
836 | mirrors = mirror_from_string(bb.data.getVar('PREMIRRORS', self.d, True)) | 836 | elif m.try_premirror(u, ud, self.d): |
837 | mirrorpath = try_mirrors(self.d, ud, mirrors, False) | 837 | mirrors = mirror_from_string(bb.data.getVar('PREMIRRORS', self.d, True)) |
838 | if mirrorpath and os.path.basename(mirrorpath) == os.path.basename(ud.localpath): | 838 | mirrorpath = try_mirrors(self.d, ud, mirrors, False) |
839 | localpath = mirrorpath | 839 | if mirrorpath and os.path.basename(mirrorpath) == os.path.basename(ud.localpath): |
840 | elif mirrorpath and os.path.exists(mirrorpath) and not mirrorpath.startswith(self.d.getVar("DL_DIR", True)): | 840 | localpath = mirrorpath |
841 | os.symlink(mirrorpath, os.path.join(self.d.getVar("DL_DIR", True), os.path.basename(mirrorpath))) | 841 | elif mirrorpath and os.path.exists(mirrorpath) and not mirrorpath.startswith(self.d.getVar("DL_DIR", True)): |
842 | 842 | os.symlink(mirrorpath, os.path.join(self.d.getVar("DL_DIR", True), os.path.basename(mirrorpath))) | |
843 | if bb.data.getVar("BB_FETCH_PREMIRRORONLY", self.d, True) is None: | 843 | |
844 | if not localpath and m.need_update(u, ud, self.d): | 844 | if bb.data.getVar("BB_FETCH_PREMIRRORONLY", self.d, True) is None: |
845 | if not localpath and m.need_update(u, ud, self.d): | ||
846 | try: | ||
847 | m.download(u, ud, self.d) | ||
848 | if hasattr(m, "build_mirror_data"): | ||
849 | m.build_mirror_data(u, ud, self.d) | ||
850 | localpath = ud.localpath | ||
851 | |||
852 | except BBFetchException: | ||
853 | # Remove any incomplete file | ||
854 | bb.utils.remove(ud.localpath) | ||
855 | mirrors = mirror_from_string(bb.data.getVar('MIRRORS', self.d, True)) | ||
856 | localpath = try_mirrors (self.d, ud, mirrors) | ||
857 | |||
858 | if not localpath or not os.path.exists(localpath): | ||
859 | raise FetchError("Unable to fetch URL %s from any source." % u, u) | ||
860 | |||
861 | # The local fetcher can return an alternate path so we symlink | ||
862 | if os.path.exists(localpath) and not os.path.exists(ud.localpath): | ||
863 | os.symlink(localpath, ud.localpath) | ||
864 | |||
865 | if os.path.exists(ud.donestamp): | ||
866 | # Touch the done stamp file to show active use of the download | ||
845 | try: | 867 | try: |
846 | m.download(u, ud, self.d) | 868 | os.utime(ud.donestamp, None) |
847 | if hasattr(m, "build_mirror_data"): | 869 | except: |
848 | m.build_mirror_data(u, ud, self.d) | 870 | # Errors aren't fatal here |
849 | localpath = ud.localpath | 871 | pass |
850 | 872 | else: | |
851 | except BBFetchException: | 873 | # Only check the checksums if we've not seen this item before, then create the stamp |
852 | # Remove any incomplete file | 874 | verify_checksum(u, ud, self.d) |
853 | bb.utils.remove(ud.localpath) | 875 | open(ud.donestamp, 'w').close() |
854 | mirrors = mirror_from_string(bb.data.getVar('MIRRORS', self.d, True)) | ||
855 | localpath = try_mirrors (self.d, ud, mirrors) | ||
856 | |||
857 | if not localpath or not os.path.exists(localpath): | ||
858 | raise FetchError("Unable to fetch URL %s from any source." % u, u) | ||
859 | |||
860 | # The local fetcher can return an alternate path so we symlink | ||
861 | if os.path.exists(localpath) and not os.path.exists(ud.localpath): | ||
862 | os.symlink(localpath, ud.localpath) | ||
863 | |||
864 | if os.path.exists(ud.donestamp): | ||
865 | # Touch the done stamp file to show active use of the download | ||
866 | try: | ||
867 | os.utime(ud.donestamp, None) | ||
868 | except: | ||
869 | # Errors aren't fatal here | ||
870 | pass | ||
871 | else: | ||
872 | # Only check the checksums if we've not seen this item before, then create the stamp | ||
873 | verify_checksum(u, ud, self.d) | ||
874 | open(ud.donestamp, 'w').close() | ||
875 | 876 | ||
876 | bb.utils.unlockfile(lf) | 877 | finally: |
878 | bb.utils.unlockfile(lf) | ||
877 | 879 | ||
878 | def checkstatus(self, urls = []): | 880 | def checkstatus(self, urls = []): |
879 | """ | 881 | """ |