]> git.saurik.com Git - apt.git/blobdiff - ftparchive/cachedb.h
releasing package apt version 1.0.9.1
[apt.git] / ftparchive / cachedb.h
index 4e33c863505f02a0d5a832bd85fdab60d27bdadb..29d710d2c51292d6d43cfbe8a982f5356d1bc30f 100644 (file)
@@ -41,7 +41,7 @@ class CacheDB
    std::string DBFile;
 
    // Generate a key for the DB of a given type
-   inline void InitQuery(const char *Type)
+   void _InitQuery(const char *Type)
    {
       memset(&Key,0,sizeof(Key));
       memset(&Data,0,sizeof(Data));
@@ -49,6 +49,19 @@ class CacheDB
       Key.size = snprintf(TmpKey,sizeof(TmpKey),"%s:%s",FileName.c_str(), Type);
    }
    
+   void InitQueryStats() {
+      _InitQuery("st");
+   }
+   void InitQuerySource() {
+      _InitQuery("cs");
+   }
+   void InitQueryControl() {
+      _InitQuery("cl");
+   }
+   void InitQueryContent() {
+      _InitQuery("cn");
+   }
+
    inline bool Get() 
    {
       return Dbp->get(Dbp,0,&Key,&Data,0) == 0;
@@ -72,8 +85,12 @@ class CacheDB
    bool OpenDebFile();
    void CloseDebFile();
 
-   bool GetFileStat(bool const &doStat = false);
+   // GetCurStat needs some compat code, see lp #1274466)
+   bool GetCurStatCompatOldFormat();
+   bool GetCurStatCompatNewFormat();
    bool GetCurStat();
+
+   bool GetFileStat(bool const &doStat = false);
    bool LoadControl();
    bool LoadContents(bool const &GenOnly);
    bool LoadSource();
@@ -88,6 +105,20 @@ class CacheDB
                   FlSHA512=(1<<6), FlSource=(1<<7),
    };
 
+   // the on-disk format changed (FileSize increased to 64bit) in 
+   // commit 650faab0 which will lead to corruption with old caches
+   struct StatStoreOldFormat
+   {
+      uint32_t Flags;
+      uint32_t mtime;
+      uint32_t FileSize;
+      uint8_t  MD5[16];
+      uint8_t  SHA1[20];
+      uint8_t  SHA256[32];
+   } CurStatOldFormat;
+
+   // WARNING: this struct is read/written to the DB so do not change the
+   //          layout of the fields (see lp #1274466), only append to it
    struct StatStore
    {
       uint32_t Flags;
@@ -143,7 +174,7 @@ class CacheDB
                SHA512Bytes(0),Packages(0), Misses(0), DeLinkBytes(0) {};
    } Stats;
    
-   bool ReadyDB(std::string const &DB);
+   bool ReadyDB(std::string const &DB = "");
    inline bool DBFailed() {return Dbp != 0 && DBLoaded == false;};
    inline bool Loaded() {return DBLoaded == true;};
    
@@ -167,8 +198,8 @@ class CacheDB
    
    bool Clean();
    
-   CacheDB(std::string const &DB) : Dbp(0), Fd(NULL), DebFile(0) {TmpKey[0]='\0'; ReadyDB(DB);};
-   ~CacheDB() {ReadyDB(std::string()); delete DebFile;};
+   CacheDB(std::string const &DB);
+   ~CacheDB();
 };
     
 #endif