Przeglądaj źródła

use pkgAcquire::GetLock instead of own code

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
David Kalnischkies 11 lat temu
rodzic
commit
7e04a6bf23
2 zmienionych plików z 4 dodań i 20 usunięć
  1. 2 0
      apt-pkg/acquire.cc
  2. 2 20
      cmdline/apt-get.cc

+ 2 - 0
apt-pkg/acquire.cc

@@ -152,6 +152,8 @@ bool pkgAcquire::GetLock(std::string const &Lock)
       return true;
       return true;
 
 
    // Lock the directory this acquire object will work in
    // Lock the directory this acquire object will work in
+   if (LockFD != -1)
+      close(LockFD);
    LockFD = ::GetLock(flCombine(Lock, "lock"));
    LockFD = ::GetLock(flCombine(Lock, "lock"));
    if (LockFD == -1)
    if (LockFD == -1)
       return _error->Error(_("Unable to lock directory %s"), Lock.c_str());
       return _error->Error(_("Unable to lock directory %s"), Lock.c_str());

+ 2 - 20
cmdline/apt-get.cc

@@ -558,30 +558,12 @@ static bool DoClean(CommandLine &)
       return true;
       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;
    pkgAcquire Fetcher;
+   Fetcher.GetLock(archivedir);
    Fetcher.Clean(archivedir);
    Fetcher.Clean(archivedir);
    Fetcher.Clean(archivedir + "partial/");
    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/");
    Fetcher.Clean(listsdir + "partial/");
 
 
    pkgCacheFile::RemoveCaches();
    pkgCacheFile::RemoveCaches();