summaryrefslogtreecommitdiff
path: root/ftparchive/cachedb.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-06-04 12:39:36 +0200
committerMichael Vogt <mvo@debian.org>2014-06-12 08:47:09 +0200
commit72675582997ff6daede62475e232c639ff0965a3 (patch)
treebb87b3f830c421595ef3eda4288425c7628866a2 /ftparchive/cachedb.cc
parent826c5fa7b541e93928791470e5df9342cb7db5ed (diff)
Add compat mode for old (32bit FileSize) CacheDB (LP: #1274466)
Diffstat (limited to 'ftparchive/cachedb.cc')
-rw-r--r--ftparchive/cachedb.cc69
1 files changed, 59 insertions, 10 deletions
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index e56deae1e..c3a4adcbc 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -86,7 +86,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;
@@ -175,6 +175,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
@@ -185,19 +224,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)
{
- CurStat.Flags = 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))
+ {
+ 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);
}