summaryrefslogtreecommitdiff
path: root/ftparchive/cachedb.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-04-04 14:30:17 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-04-04 14:30:17 +0200
commitce928105d7279c5604f034740b04dc6a745fb859 (patch)
treef31261fdbbae13f1b40f99cf42a1d79d677098a7 /ftparchive/cachedb.cc
parent62f1ee1cc7a5e16ca0cbfbee3c00cefab1892f87 (diff)
Implement CacheDB for source packages in apt-ftparchive
Diffstat (limited to 'ftparchive/cachedb.cc')
-rw-r--r--ftparchive/cachedb.cc146
1 files changed, 101 insertions, 45 deletions
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index 523c6b5fa..a63b5b9d9 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -20,6 +20,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/debfile.h>
+#include <apt-pkg/gpgv.h>
#include <netinet/in.h> // htonl, etc
#include <ctype.h>
@@ -99,13 +100,32 @@ bool CacheDB::OpenFile()
Fd = new FileFd(FileName,FileFd::ReadOnly);
if (_error->PendingError() == true)
{
- delete Fd;
- Fd = NULL;
- return false;
+ CloseFile();
+ return false;
}
return true;
}
/*}}}*/
+void CacheDB::CloseFile()
+{
+ delete Fd;
+ Fd = NULL;
+}
+
+bool CacheDB::OpenDebFile()
+{
+ DebFile = new debDebFile(*Fd);
+ if (_error->PendingError() == true)
+ return false;
+ return true;
+}
+
+void CacheDB::CloseDebFile()
+{
+ delete DebFile;
+ DebFile = NULL;
+}
+
// CacheDB::GetFileStat - Get stats from the file /*{{{*/
// ---------------------------------------------------------------------
/* This gets the size from the database if it's there. If we need
@@ -168,56 +188,94 @@ bool CacheDB::GetCurStat()
/*}}}*/
// CacheDB::GetFileInfo - Get all the info about the file /*{{{*/
// ---------------------------------------------------------------------
-bool CacheDB::GetFileInfo(std::string const &FileName, bool const &DoControl, bool const &DoContents,
- bool const &GenContentsOnly, bool const &DoMD5, bool const &DoSHA1,
- bool const &DoSHA256, bool const &DoSHA512,
+bool CacheDB::GetFileInfo(std::string const &FileName, bool const &DoControl,
+ bool const &DoContents,
+ bool const &GenContentsOnly,
+ bool const &DoSource,
+ bool const &DoMD5, bool const &DoSHA1,
+ bool const &DoSHA256, bool const &DoSHA512,
bool const &checkMtime)
{
- this->FileName = FileName;
+ bool result = true;
+ this->FileName = FileName;
- if (GetCurStat() == false)
+ if (GetCurStat() == false)
{
- return false;
+ return false;
}
OldStat = CurStat;
- if (GetFileStat(checkMtime) == false)
- {
- delete Fd;
- Fd = NULL;
- return false;
- }
+ if (GetFileStat(checkMtime) == false)
+ {
+ CloseFile();
+ return false;
+ }
/* if mtime changed, update CurStat from disk */
if (checkMtime == true && OldStat.mtime != CurStat.mtime)
- CurStat.Flags = FlSize;
-
- Stats.Bytes += CurStat.FileSize;
- Stats.Packages++;
-
- if ((DoControl && LoadControl() == false)
- || (DoContents && LoadContents(GenContentsOnly) == false)
- || (DoMD5 && GetMD5(false) == false)
- || (DoSHA1 && GetSHA1(false) == false)
- || (DoSHA256 && GetSHA256(false) == false)
- || (DoSHA512 && GetSHA512(false) == false)
- )
- {
- delete Fd;
- Fd = NULL;
- delete DebFile;
- DebFile = NULL;
- return false;
- }
+ CurStat.Flags = FlSize;
- delete Fd;
- Fd = NULL;
- delete DebFile;
- DebFile = NULL;
+ Stats.Bytes += CurStat.FileSize;
+ Stats.Packages++;
- return true;
+ if ((DoControl && LoadControl() == false)
+ || (DoContents && LoadContents(GenContentsOnly) == false)
+ || (DoSource && LoadSource() == false)
+ || (DoMD5 && GetMD5(false) == false)
+ || (DoSHA1 && GetSHA1(false) == false)
+ || (DoSHA256 && GetSHA256(false) == false)
+ || (DoSHA512 && GetSHA512(false) == false)
+ )
+ {
+ result = false;
+ }
+
+ CloseFile();
+ CloseDebFile();
+
+ return result;
}
/*}}}*/
+
+bool CacheDB::LoadSource()
+{
+ // Try to read the control information out of the DB.
+ if ((CurStat.Flags & FlSource) == FlSource)
+ {
+ // Lookup the control information
+ InitQuery("cs");
+ if (Get() == true && Dsc.TakeDsc(Data.data, Data.size) == true)
+ return true;
+ CurStat.Flags &= ~FlSource;
+ }
+
+ if (Fd == NULL && OpenFile() == false)
+ {
+ return false;
+ }
+
+ // Read the .dsc file
+ if (Fd == NULL)
+ {
+ if(OpenFile() == false)
+ return false;
+ }
+
+ Stats.Misses++;
+ if (Dsc.Read(FileName) == false)
+ return false;
+
+ if (Dsc.Data == 0)
+ return _error->Error(_("Failed to read .dsc"));
+
+ // Write back the control information
+ InitQuery("cs");
+ if (Put(Dsc.Data, Dsc.Length) == true)
+ CurStat.Flags |= FlSource;
+
+ return true;
+}
+
// CacheDB::LoadControl - Load Control information /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -238,11 +296,10 @@ bool CacheDB::LoadControl()
return false;
}
// Create a deb instance to read the archive
- if (DebFile == 0)
+ if (DebFile == NULL)
{
- DebFile = new debDebFile(*Fd);
- if (_error->PendingError() == true)
- return false;
+ if(OpenDebFile() == false)
+ return false;
}
Stats.Misses++;
@@ -288,8 +345,7 @@ bool CacheDB::LoadContents(bool const &GenOnly)
// Create a deb instance to read the archive
if (DebFile == 0)
{
- DebFile = new debDebFile(*Fd);
- if (_error->PendingError() == true)
+ if(OpenDebFile() == false)
return false;
}