diff options
| -rw-r--r-- | apt/cache.py | 42 | ||||
| -rw-r--r-- | debian/changelog | 2 |
2 files changed, 24 insertions, 20 deletions
diff --git a/apt/cache.py b/apt/cache.py index 9218263b..01034cf9 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -140,31 +140,35 @@ class Cache(object): if lock < 0: raise IOError, "Failed to lock %s" % lockfile - # this may as well throw a SystemError exception - if not pm.GetArchives(fetcher, self._list, self._records): - return False - # now run the fetcher, throw exception if something fails to be - # fetched - res = self._runFetcher(fetcher) - # cleanup - os.close(lock) - return res + try: + # this may as well throw a SystemError exception + if not pm.GetArchives(fetcher, self._list, self._records): + return False + # now run the fetcher, throw exception if something fails to be + # fetched + return self._runFetcher(fetcher) + finally: + os.close(lock) def update(self, fetchProgress=None): lockfile = apt_pkg.Config.FindDir("Dir::State::Lists") + "lock" lock = apt_pkg.GetLock(lockfile) if lock < 0: raise IOError, "Failed to lock %s" % lockfile - if fetchProgress == None: - fetchProgress = apt.progress.FetchProgress() - fetcher = apt_pkg.GetAcquire(fetchProgress) - # this can throw a exception - self._list.GetIndexes(fetcher) - # now run the fetcher, throw exception if something fails to be - # fetched - if self._runFetcher(fetcher) == fetcher.ResultContinue: - return True - return False + + try: + if fetchProgress == None: + fetchProgress = apt.progress.FetchProgress() + fetcher = apt_pkg.GetAcquire(fetchProgress) + # this can throw a exception + self._list.GetIndexes(fetcher) + # now run the fetcher, throw exception if something fails to be + # fetched + if self._runFetcher(fetcher) == fetcher.ResultContinue: + return True + return False + finally: + os.close(lock) def installArchives(self, pm, installProgress): installProgress.startUpdate() diff --git a/debian/changelog b/debian/changelog index 23f586d9..e621b8d6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,7 @@ python-apt (0.6.16.2) unstable; urgency=low * apt/cache.py: - return useful values on Cache.update() * apt/cache.py, apt/package.py: fix various pychecker warnings - + * apt/cache.py: Release locks on failure (thanks to Colin Watson) -- |
