From 4e7cf23803ea29eb90b9c663cb6ded845067a6c7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 21 Mar 2006 15:08:34 +0100 Subject: * fix lock-releasing on exception (thanks to kamion) --- apt/cache.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'apt/cache.py') 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() -- cgit v1.2.3