ソースを参照

cleanup partial directory of lists in apt-get clean

Not really the intended usecase for apt-get clean, but users expect it
to help them in recovery and it can't really hurt as this directory
should be empty if everything was fine and proper anyway.

Closes: #762889
David Kalnischkies 11 年 前
コミット
20e6965ad6
共有2 個のファイルを変更した54 個の追加6 個の削除を含む
  1. 20 6
      cmdline/apt-get.cc
  2. 34 0
      test/integration/test-apt-get-clean

+ 20 - 6
cmdline/apt-get.cc

@@ -549,30 +549,44 @@ static bool DoDSelectUpgrade(CommandLine &)
 static bool DoClean(CommandLine &)
 {
    std::string const archivedir = _config->FindDir("Dir::Cache::archives");
-   std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
-   std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
+   std::string const listsdir = _config->FindDir("Dir::state::lists");
 
    if (_config->FindB("APT::Get::Simulate") == true)
    {
+      std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache");
+      std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache");
       cout << "Del " << archivedir << "* " << archivedir << "partial/*"<< endl
+	   << "Del " << listsdir << "partial/*" << endl
 	   << "Del " << pkgcache << " " << srcpkgcache << endl;
       return true;
    }
-   
+
+   bool const NoLocking = _config->FindB("Debug::NoLocking",false);
    // Lock the archive directory
    FileFd Lock;
-   if (_config->FindB("Debug::NoLocking",false) == false)
+   if (NoLocking == false)
    {
       int lock_fd = GetLock(archivedir + "lock");
       if (lock_fd < 0)
-	 return _error->Error(_("Unable to lock the download directory"));
+	 return _error->Error(_("Unable to lock directory %s"), archivedir.c_str());
       Lock.Fd(lock_fd);
    }
-   
+
    pkgAcquire Fetcher;
    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.Clean(listsdir + "partial/");
+
    pkgCacheFile::RemoveCaches();
 
    return true;

+ 34 - 0
test/integration/test-apt-get-clean

@@ -0,0 +1,34 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture 'amd64'
+
+insertpackage 'testing' 'foo' 'all' '1'
+insertpackage 'unstable' 'foo' 'all' '2'
+insertinstalledpackage 'foo' 'all' '3'
+
+setupaptarchive
+
+# nothing to do always works
+testsuccess aptget clean
+
+# generate some dirt and clean it up
+touch rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
+touch rootdir/var/cache/apt/archives/foo_1_all.deb
+touch rootdir/var/cache/apt/archives/foo_2_all.deb
+touch rootdir/var/cache/apt/archives/foo_3_all.deb
+touch rootdir/var/cache/apt/archives/foo_4_all.deb
+
+testsuccess aptget clean
+
+testsuccess test ! -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
+testsuccess test ! -e rootdir/var/cache/apt/archives/foo_1_all.deb
+testsuccess test ! -e rootdir/var/cache/apt/archives/foo_2_all.deb
+testsuccess test ! -e rootdir/var/cache/apt/archives/foo_3_all.deb
+testsuccess test ! -e rootdir/var/cache/apt/archives/foo_4_all.deb
+
+