[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#596793: python-apt: Add a lock argument to apt.Cache.update and apt.Cache.commit



Here is small patch for the current debian-sid branch.
=== modified file 'apt/cache.py'
--- apt/cache.py	2010-09-03 10:08:20 +0000
+++ apt/cache.py	2010-09-14 08:00:13 +0000
@@ -261,14 +261,15 @@
             raise FetchFailedException(err_msg)
         return res
 
-    def _fetch_archives(self, fetcher, pm):
+    def _fetch_archives(self, fetcher, pm, lock_archives=True):
         """ fetch the needed archives """
 
         # get lock
-        lockfile = apt_pkg.config.find_dir("Dir::Cache::Archives") + "lock"
-        lock = apt_pkg.get_lock(lockfile)
-        if lock < 0:
-            raise LockFailedException("Failed to lock %s" % lockfile)
+        if lock_archives:
+            lockfile = apt_pkg.config.find_dir("Dir::Cache::Archives") + "lock"
+            lock = apt_pkg.get_lock(lockfile)
+            if lock < 0:
+                raise LockFailedException("Failed to lock %s" % lockfile)
 
         try:
             # this may as well throw a SystemError exception
@@ -278,7 +279,8 @@
             # fetched
             return self._run_fetcher(fetcher)
         finally:
-            os.close(lock)
+            if lock_archives:
+                os.close(lock)
 
     def is_virtual_package(self, pkgname):
         """Return whether the package is a virtual package."""
@@ -327,7 +329,7 @@
 
     @deprecated_args
     def update(self, fetch_progress=None, pulse_interval=0,
-               raise_on_error=True, sources_list=None):
+               raise_on_error=True, sources_list=None, lock_lists=True):
         """Run the equivalent of apt-get update.
 
         The first parameter *fetch_progress* may be set to an instance of
@@ -335,12 +337,15 @@
         .
         sources_list -- Update a alternative sources.list than the default.
          Note that the sources.list.d directory is ignored in this case
+
+        If the optional 'lock_lists' argument is set to False, the lock of
+        the package lists won't be acquired.
         """
-        lockfile = apt_pkg.config.find_dir("Dir::State::Lists") + "lock"
-        lock = apt_pkg.get_lock(lockfile)
-
-        if lock < 0:
-            raise LockFailedException("Failed to lock %s" % lockfile)
+        if lock_lists:
+            lockfile = apt_pkg.config.find_dir("Dir::State::Lists") + "lock"
+            lock = apt_pkg.get_lock(lockfile)
+            if lock < 0:
+                raise LockFailedException("Failed to lock %s" % lockfile)
 
         if sources_list:
             old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
@@ -367,7 +372,8 @@
             else:
                 return res
         finally:
-            os.close(lock)
+            if lock_lists:
+                os.close(lock)
             if sources_list:
                 apt_pkg.config.set("Dir::Etc::sourcelist", old_sources_list)
                 apt_pkg.config.set("Dir::Etc::sourceparts", old_sources_list_d)
@@ -395,7 +401,8 @@
         return res
 
     @deprecated_args
-    def commit(self, fetch_progress=None, install_progress=None):
+    def commit(self, fetch_progress=None, install_progress=None,
+               lock_archives=None):
         """Apply the marked changes to the cache.
 
         The first parameter, *fetch_progress*, refers to a FetchProgress()
@@ -404,6 +411,9 @@
 
         The second parameter, *install_progress*, is a
         apt.progress.InstallProgress() object.
+
+        If the optional parameter *lock_archive* is set to False, the lock
+        to the download direcotry won't be acquired.
         """
         # FIXME:
         # use the new acquire/pkgmanager interface here,
@@ -421,7 +431,7 @@
         fetcher = apt_pkg.Acquire(fetch_progress)
         while True:
             # fetch archives first
-            res = self._fetch_archives(fetcher, pm)
+            res = self._fetch_archives(fetcher, pm, lock_archives)
 
             # then install
             res = self.install_archives(pm, install_progress)

Attachment: signature.asc
Description: Digital signature


Reply to: