1 // -*- mode: cpp; mode: fold -*-
3 // $Id: cachedb.h,v 1.4 2004/05/08 19:41:01 mdz Exp $
4 /* ######################################################################
8 Simple uniform interface to a cache database.
10 ##################################################################### */
16 #pragma interface "cachedb.h"
21 #include <apt-pkg/debfile.h>
32 // Database state/access
41 // Generate a key for the DB of a given type
42 inline void InitQuery(const char *Type
)
44 memset(&Key
,0,sizeof(Key
));
45 memset(&Data
,0,sizeof(Data
));
47 Key
.size
= snprintf(TmpKey
,sizeof(TmpKey
),"%s:%s",Type
,FileName
.c_str());
52 return Dbp
->get(Dbp
,0,&Key
,&Data
,0) == 0;
54 inline bool Put(const void *In
,unsigned long Length
)
59 Data
.data
= (void *)In
;
60 if (DBLoaded
== true && (errno
= Dbp
->put(Dbp
,0,&Key
,&Data
,0)) != 0)
68 // Stat info stored in the DB, Fixed types since it is written to disk.
69 enum FlagList
{FlControl
= (1<<0),FlMD5
=(1<<1),FlContents
=(1<<2)};
75 struct StatStore OldStat
;
85 // Data collection helpers
86 debDebFile::MemControlExtract Control
;
87 ContentsExtract Contents
;
94 unsigned long Packages
;
96 unsigned long DeLinkBytes
;
98 inline void Add(const Stats
&S
) {Bytes
+= S
.Bytes
; MD5Bytes
+= S
.MD5Bytes
;
99 Packages
+= S
.Packages
; Misses
+= S
.Misses
; DeLinkBytes
+= S
.DeLinkBytes
;};
100 Stats() : Bytes(0), MD5Bytes(0), Packages(0), Misses(0), DeLinkBytes(0) {};
103 bool ReadyDB(string DB
);
104 inline bool DBFailed() {return Dbp
!= 0 && DBLoaded
== false;};
105 inline bool Loaded() {return DBLoaded
== true;};
107 bool SetFile(string FileName
,struct stat St
,FileFd
*Fd
);
109 bool LoadContents(bool GenOnly
);
110 bool GetMD5(string
&MD5Res
,bool GenOnly
);
115 CacheDB(string DB
) : Dbp(0), DebFile(0) {ReadyDB(DB
);};
116 ~CacheDB() {ReadyDB(string()); delete DebFile
;};