]> git.saurik.com Git - apt.git/commitdiff
use pkgAcquire::GetLock instead of own code
authorDavid Kalnischkies <david@kalnischkies.de>
Sun, 9 Nov 2014 18:04:54 +0000 (19:04 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Sun, 9 Nov 2014 20:45:55 +0000 (21:45 +0100)
Do the same with less code in apt-get. This especially ensures that the
lock file (and the parent directories) exist before we are trying to
lock. It also means that clean now creates the directories if they are
missing so we returned to a proper clean state now.

Git-Dch: Ignore

apt-pkg/acquire.cc
cmdline/apt-get.cc

index 2c89c2deade4c42e02019d160fb12990a22ddf20..07c4646f50fc9ba80a3434c7f17d615f4bbbb6ad 100644 (file)
@@ -152,6 +152,8 @@ bool pkgAcquire::GetLock(std::string const &Lock)
       return true;
 
    // Lock the directory this acquire object will work in
+   if (LockFD != -1)
+      close(LockFD);
    LockFD = ::GetLock(flCombine(Lock, "lock"));
    if (LockFD == -1)
       return _error->Error(_("Unable to lock directory %s"), Lock.c_str());
index a9053bdfdea978cf61ef59cbdcc3d4f9efb769ee..eab79226406de71af9af51737009311e0c06723e 100644 (file)
@@ -558,30 +558,12 @@ static bool DoClean(CommandLine &)
       return true;
    }
 
-   bool const NoLocking = _config->FindB("Debug::NoLocking",false);
-   // Lock the archive directory
-   FileFd Lock;
-   if (NoLocking == false)
-   {
-      int lock_fd = GetLock(archivedir + "lock");
-      if (lock_fd < 0)
-        return _error->Error(_("Unable to lock directory %s"), archivedir.c_str());
-      Lock.Fd(lock_fd);
-   }
-
    pkgAcquire Fetcher;
+   Fetcher.GetLock(archivedir);
    Fetcher.Clean(archivedir);
    Fetcher.Clean(archivedir + "partial/");
 
-   if (NoLocking == false)
-   {
-      Lock.Close();
-      int lock_fd = GetLock(listsdir + "lock");
-      if (lock_fd < 0)
-        return _error->Error(_("Unable to lock directory %s"), listsdir.c_str());
-      Lock.Fd(lock_fd);
-   }
-
+   Fetcher.GetLock(listsdir);
    Fetcher.Clean(listsdir + "partial/");
 
    pkgCacheFile::RemoveCaches();