]> git.saurik.com Git - apt.git/commitdiff
ensure clean works
authorMichael Vogt <mvo@ubuntu.com>
Fri, 4 Apr 2014 15:09:43 +0000 (17:09 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Fri, 4 Apr 2014 15:09:43 +0000 (17:09 +0200)
ftparchive/apt-ftparchive.cc
ftparchive/cachedb.cc
test/integration/test-apt-ftparchive-cachedb
test/integration/test-apt-ftparchive-src-cachedb

index c1614398b1104bcfba01f0031f1a1f3c30f45176..74fc7681f534326240efb90f2f901ee53c2277b6 100644 (file)
@@ -957,23 +957,33 @@ static bool Clean(CommandLine &CmdL)
 
    // Sort by cache DB to improve IO locality.
    stable_sort(PkgList.begin(),PkgList.end(),PackageMap::DBCompare());
+   stable_sort(PkgList.begin(),PkgList.end(),PackageMap::SrcDBCompare());
 
    string CacheDir = Setup.FindDir("Dir::CacheDir");
    
    for (vector<PackageMap>::iterator I = PkgList.begin(); I != PkgList.end(); )
    {
-      c0out << I->BinCacheDB << endl;
+      if(I->BinCacheDB != "")
+         c0out << I->BinCacheDB << endl;
+      if(I->SrcCacheDB != "")
+         c0out << I->SrcCacheDB << endl;
       CacheDB DB(flCombine(CacheDir,I->BinCacheDB));
+      CacheDB DB_SRC(flCombine(CacheDir,I->SrcCacheDB));
       if (DB.Clean() == false)
         _error->DumpErrors();
+      if (DB_SRC.Clean() == false)
+        _error->DumpErrors();
       
       string CacheDB = I->BinCacheDB;
-      for (; I != PkgList.end() && I->BinCacheDB == CacheDB; ++I)
-         ;
+      string SrcCacheDB = I->SrcCacheDB;
+      while(I != PkgList.end() && 
+            I->BinCacheDB == CacheDB && 
+            I->SrcCacheDB == SrcCacheDB)
+         ++I;
+
    }
 
-   // FIXME: clean for the SourcesDB
-   
+  
    return true;
 }
                                                                        /*}}}*/
index 539ed671bf354ea22cf3804870c73c999b4e2bfc..f63aa88ab06e4a4baf410f69d7700f1abf14972c 100644 (file)
@@ -264,10 +264,11 @@ bool CacheDB::LoadSource()
       // Lookup the control information
       InitQuery("cs");
       if (Get() == true && Dsc.TakeDsc(Data.data, Data.size) == true)
+      {
            return true;
+      }
       CurStat.Flags &= ~FlSource;
    }
-   
    if (OpenFile() == false)
       return false;
 
@@ -551,16 +552,24 @@ bool CacheDB::Clean()
       {
          if (stringcmp(Colon + 1, (char *)Key.data+Key.size,"st") == 0 ||
              stringcmp(Colon + 1, (char *)Key.data+Key.size,"cl") == 0 ||
+             stringcmp(Colon + 1, (char *)Key.data+Key.size,"cs") == 0 ||
              stringcmp(Colon + 1, (char *)Key.data+Key.size,"cn") == 0)
         {
-            if (FileExists(std::string((const char *)Key.data,Colon)) == true)
-               continue;            
+            std::string FileName = std::string((const char *)Key.data,Colon);
+            if (FileExists(FileName) == true) {
+               continue;
+            }
         }
       }
-      
       Cursor->c_del(Cursor,0);
    }
-   Dbp->compact(Dbp, NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL);
+   int res = Dbp->compact(Dbp, NULL, NULL, NULL, NULL, DB_FREE_SPACE, NULL);
+   if (res < 0)
+      _error->Warning("compact failed with result %i", res);
+
+   if(_config->FindB("Debug::APT::FTPArchive::Clean", false) == true)
+      Dbp->stat_print(Dbp, 0);
+
 
    return true;
 }
index 2a3bfce9967377dd68f8a65d8c980a187198b209..147272a2c4d0f5599b0bfb1b60f779514ef7eea9 100755 (executable)
@@ -91,3 +91,10 @@ ensure_correct_contents_file
 testequal " Misses in Cache: 0
  dists/test/Contents-i386: New 402 B  Misses in Cache: 0" grep Misses stats-out.txt
 
+# and clean
+rm -rf aptarchive/pool/main/*
+testequal "packages-main-i386.db" aptftparchive clean ftparchive.conf
+aptftparchive clean ftparchive.conf -o Debug::APT::FTPArchive::Clean=1 > clean-out.txt 2>&1 
+testequal "0   Number of unique keys in the tree" grep unique clean-out.txt
+testequal "packages-main-i386.db" grep packages-main-i386.db clean-out.txt
+
index 3a5507c213e2f21e622637dc9474e2741359e7eb..9cc0a98dedaf1e82e0640cc89b412de190a59f44 100755 (executable)
@@ -159,4 +159,10 @@ dd if=/dev/zero of="aptarchive/pool/invalid/toobig_1.0.dsc" bs=1k count=129 2>/d
 testequal "
 E: DSC file 'aptarchive/pool/invalid/toobig_1.0.dsc' is too large!" aptftparchive sources aptarchive/pool/invalid
 
+# ensure clean works
+rm -f aptarchive/pool/main/*
+aptftparchive clean apt-ftparchive.conf -o Debug::APT::FTPArchive::Clean=1 > clean-out.txt 2>&1 
+testequal "0   Number of unique keys in the tree" grep unique clean-out.txt
+testequal "sources-main.db" grep sources-main.db clean-out.txt
+