summaryrefslogtreecommitdiff
path: root/ftparchive
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-06-18 08:32:47 +0200
committerMichael Vogt <mvo@debian.org>2014-06-18 08:32:47 +0200
commitaa0bd601ea3db281187275bbbece760d85ff29d9 (patch)
treec84bebb3966255cdae36562024592c6b4eb6a2f2 /ftparchive
parent80624be7c54aec6ed98ee254366155024fca1a71 (diff)
parent6074bc9ba4ecdd08674a828bdb46323b5d8bf957 (diff)
downloadapt-aa0bd601ea3db281187275bbbece760d85ff29d9.tar.gz
Merge branch 'debian/sid' into debian/experimental
Conflicts: debian/changelog
Diffstat (limited to 'ftparchive')
-rw-r--r--ftparchive/cachedb.cc82
-rw-r--r--ftparchive/cachedb.h26
-rw-r--r--ftparchive/contents.cc13
-rw-r--r--ftparchive/contents.h4
-rw-r--r--ftparchive/writer.h6
5 files changed, 112 insertions, 19 deletions
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index be54ea62c..7770a3244 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -34,6 +34,19 @@
#include <apti18n.h>
/*}}}*/
+CacheDB::CacheDB(std::string const &DB)
+ : Dbp(0), Fd(NULL), DebFile(0)
+{
+ TmpKey[0]='\0';
+ ReadyDB(DB);
+};
+
+CacheDB::~CacheDB()
+{
+ ReadyDB();
+ delete DebFile;
+};
+
// CacheDB::ReadyDB - Ready the DB2 /*{{{*/
// ---------------------------------------------------------------------
/* This opens the DB2 file for caching package information */
@@ -88,7 +101,7 @@ bool CacheDB::ReadyDB(std::string const &DB)
return _error->Error(_("Unable to open DB file %s: %s"),DB.c_str(), db_strerror(err));
}
}
-
+
DBFile = DB;
DBLoaded = true;
return true;
@@ -177,6 +190,45 @@ bool CacheDB::GetFileStat(bool const &doStat)
return true;
}
/*}}}*/
+// CacheDB::GetCurStatCompatOldFormat /*{{{*/
+// ---------------------------------------------------------------------
+/* Read the old (32bit FileSize) StateStore format from disk */
+bool CacheDB::GetCurStatCompatOldFormat()
+{
+ InitQueryStats();
+ Data.data = &CurStatOldFormat;
+ Data.flags = DB_DBT_USERMEM;
+ Data.ulen = sizeof(CurStatOldFormat);
+ if (Get() == false)
+ {
+ CurStat.Flags = 0;
+ } else {
+ CurStat.Flags = CurStatOldFormat.Flags;
+ CurStat.mtime = CurStatOldFormat.mtime;
+ CurStat.FileSize = CurStatOldFormat.FileSize;
+ memcpy(CurStat.MD5, CurStatOldFormat.MD5, sizeof(CurStat.MD5));
+ memcpy(CurStat.SHA1, CurStatOldFormat.SHA1, sizeof(CurStat.SHA1));
+ memcpy(CurStat.SHA256, CurStatOldFormat.SHA256, sizeof(CurStat.SHA256));
+ }
+ return true;
+}
+ /*}}}*/
+// CacheDB::GetCurStatCompatOldFormat /*{{{*/
+// ---------------------------------------------------------------------
+/* Read the new (64bit FileSize) StateStore format from disk */
+bool CacheDB::GetCurStatCompatNewFormat()
+{
+ InitQueryStats();
+ Data.data = &CurStat;
+ Data.flags = DB_DBT_USERMEM;
+ Data.ulen = sizeof(CurStat);
+ if (Get() == false)
+ {
+ CurStat.Flags = 0;
+ }
+ return true;
+}
+ /*}}}*/
// CacheDB::GetCurStat - Set the CurStat variable. /*{{{*/
// ---------------------------------------------------------------------
/* Sets the CurStat variable. Either to 0 if no database is used
@@ -187,19 +239,29 @@ bool CacheDB::GetCurStat()
if (DBLoaded)
{
- /* First see if there is anything about it
- in the database */
-
- /* Get the flags (and mtime) */
+ // do a first query to just get the size of the data on disk
InitQueryStats();
- // Ensure alignment of the returned structure
Data.data = &CurStat;
- Data.ulen = sizeof(CurStat);
Data.flags = DB_DBT_USERMEM;
- if (Get() == false)
+ Data.ulen = 0;
+ Get();
+
+ if (Data.size == 0)
+ {
+ // nothing needs to be done, we just have not data for this deb
+ }
+ // check if the record is written in the old format (32bit filesize)
+ else if(Data.size == sizeof(CurStatOldFormat))
{
- CurStat.Flags = 0;
- }
+ GetCurStatCompatOldFormat();
+ }
+ else if(Data.size == sizeof(CurStat))
+ {
+ GetCurStatCompatNewFormat();
+ } else {
+ return _error->Error("Cache record size mismatch (%ul)", Data.size);
+ }
+
CurStat.Flags = ntohl(CurStat.Flags);
CurStat.FileSize = ntohl(CurStat.FileSize);
}
diff --git a/ftparchive/cachedb.h b/ftparchive/cachedb.h
index 14dba5578..b40fd7df7 100644
--- a/ftparchive/cachedb.h
+++ b/ftparchive/cachedb.h
@@ -86,8 +86,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();
@@ -99,6 +103,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;
@@ -150,7 +168,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;};
@@ -171,8 +189,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
diff --git a/ftparchive/contents.cc b/ftparchive/contents.cc
index 7a1fb779e..91dd2b8bd 100644
--- a/ftparchive/contents.cc
+++ b/ftparchive/contents.cc
@@ -302,7 +302,18 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
DoPrint(Out,Top->BTreeRight,Buf);
}
/*}}}*/
-
+// ContentsExtract Constructor /*{{{*/
+ContentsExtract::ContentsExtract()
+ : Data(0), MaxSize(0), CurSize(0)
+{
+};
+ /*}}}*/
+// ContentsExtract Destructor /*{{{*/
+ContentsExtract::~ContentsExtract()
+{
+ free(Data);
+};
+ /*}}}*/
// ContentsExtract::Read - Read the archive /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/ftparchive/contents.h b/ftparchive/contents.h
index dbbb83350..f58e3278e 100644
--- a/ftparchive/contents.h
+++ b/ftparchive/contents.h
@@ -85,8 +85,8 @@ class ContentsExtract : public pkgDirStream
bool TakeContents(const void *Data,unsigned long long Length);
void Add(GenContents &Contents,std::string const &Package);
- ContentsExtract() : Data(0), MaxSize(0), CurSize(0) {};
- virtual ~ContentsExtract() {delete [] Data;};
+ ContentsExtract();
+ virtual ~ContentsExtract();
};
#endif
diff --git a/ftparchive/writer.h b/ftparchive/writer.h
index c62d4addf..226996475 100644
--- a/ftparchive/writer.h
+++ b/ftparchive/writer.h
@@ -126,8 +126,10 @@ class PackagesWriter : public FTWScanner
{return Over.ReadExtraOverride(File);};
virtual bool DoPackage(string FileName);
- PackagesWriter(string const &DB,string const &Overrides,string const &ExtOverrides=string(),
- string const &Arch=string());
+ PackagesWriter(string const &DB,
+ string const &Overrides,
+ string const &ExtOverrides = "",
+ string const &Arch = "");
virtual ~PackagesWriter() {};
};