summaryrefslogtreecommitdiff
path: root/ftparchive
diff options
context:
space:
mode:
Diffstat (limited to 'ftparchive')
-rw-r--r--ftparchive/apt-ftparchive.cc2
-rw-r--r--ftparchive/cachedb.cc40
-rw-r--r--ftparchive/cachedb.h20
-rw-r--r--ftparchive/contents.cc27
-rw-r--r--ftparchive/multicompress.cc58
-rw-r--r--ftparchive/multicompress.h21
-rw-r--r--ftparchive/writer.cc196
-rw-r--r--ftparchive/writer.h9
8 files changed, 232 insertions, 141 deletions
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc
index 0c29002e6..0762a2b28 100644
--- a/ftparchive/apt-ftparchive.cc
+++ b/ftparchive/apt-ftparchive.cc
@@ -949,6 +949,8 @@ int main(int argc, const char *argv[])
CommandLine::Args Args[] = {
{'h',"help","help",0},
{0,"md5","APT::FTPArchive::MD5",0},
+ {0,"sha1","APT::FTPArchive::SHA1",0},
+ {0,"sha256","APT::FTPArchive::SHA256",0},
{'v',"version","version",0},
{'d',"db","APT::FTPArchive::DB",CommandLine::HasArg},
{'s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg},
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index b04244347..7e4c2e9fe 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -16,7 +16,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
-#include <apt-pkg/sha256.h>
+#include <apt-pkg/sha2.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/configuration.h>
@@ -162,7 +162,8 @@ bool CacheDB::GetCurStat()
// ---------------------------------------------------------------------
bool CacheDB::GetFileInfo(string const &FileName, bool const &DoControl, bool const &DoContents,
bool const &GenContentsOnly, bool const &DoMD5, bool const &DoSHA1,
- bool const &DoSHA256, bool const &checkMtime)
+ bool const &DoSHA256, bool const &DoSHA512,
+ bool const &checkMtime)
{
this->FileName = FileName;
@@ -190,7 +191,9 @@ bool CacheDB::GetFileInfo(string const &FileName, bool const &DoControl, bool co
|| (DoContents && LoadContents(GenContentsOnly) == false)
|| (DoMD5 && GetMD5(false) == false)
|| (DoSHA1 && GetSHA1(false) == false)
- || (DoSHA256 && GetSHA256(false) == false))
+ || (DoSHA256 && GetSHA256(false) == false)
+ || (DoSHA512 && GetSHA512(false) == false)
+ )
{
delete Fd;
Fd = NULL;
@@ -412,6 +415,37 @@ bool CacheDB::GetSHA256(bool const &GenOnly)
return true;
}
/*}}}*/
+// CacheDB::GetSHA256 - Get the SHA256 hash /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool CacheDB::GetSHA512(bool const &GenOnly)
+{
+ // Try to read the control information out of the DB.
+ if ((CurStat.Flags & FlSHA512) == FlSHA512)
+ {
+ if (GenOnly == true)
+ return true;
+
+ SHA512Res = bytes2hex(CurStat.SHA512, sizeof(CurStat.SHA512));
+ return true;
+ }
+
+ Stats.SHA512Bytes += CurStat.FileSize;
+
+ if (Fd == NULL && OpenFile() == false)
+ {
+ return false;
+ }
+ SHA512Summation SHA512;
+ if (Fd->Seek(0) == false || SHA512.AddFD(Fd->Fd(),CurStat.FileSize) == false)
+ return false;
+
+ SHA512Res = SHA512.Result();
+ hex2bytes(CurStat.SHA512, SHA512Res.data(), sizeof(CurStat.SHA512));
+ CurStat.Flags |= FlSHA512;
+ return true;
+}
+ /*}}}*/
// CacheDB::Finish - Write back the cache structure /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/ftparchive/cachedb.h b/ftparchive/cachedb.h
index 0ba80909a..15e796325 100644
--- a/ftparchive/cachedb.h
+++ b/ftparchive/cachedb.h
@@ -70,10 +70,13 @@ class CacheDB
bool GetMD5(bool const &GenOnly);
bool GetSHA1(bool const &GenOnly);
bool GetSHA256(bool const &GenOnly);
+ bool GetSHA512(bool const &GenOnly);
// Stat info stored in the DB, Fixed types since it is written to disk.
enum FlagList {FlControl = (1<<0),FlMD5=(1<<1),FlContents=(1<<2),
- FlSize=(1<<3), FlSHA1=(1<<4), FlSHA256=(1<<5)};
+ FlSize=(1<<3), FlSHA1=(1<<4), FlSHA256=(1<<5),
+ FlSHA512=(1<<6)};
+
struct StatStore
{
uint32_t Flags;
@@ -82,6 +85,7 @@ class CacheDB
uint8_t MD5[16];
uint8_t SHA1[20];
uint8_t SHA256[32];
+ uint8_t SHA512[64];
} CurStat;
struct StatStore OldStat;
@@ -98,6 +102,7 @@ class CacheDB
string MD5Res;
string SHA1Res;
string SHA256Res;
+ string SHA512Res;
// Runtime statistics
struct Stats
@@ -106,14 +111,21 @@ class CacheDB
double MD5Bytes;
double SHA1Bytes;
double SHA256Bytes;
+ double SHA512Bytes;
unsigned long Packages;
unsigned long Misses;
unsigned long DeLinkBytes;
inline void Add(const Stats &S) {
- Bytes += S.Bytes; MD5Bytes += S.MD5Bytes; SHA1Bytes += S.SHA1Bytes;
+ Bytes += S.Bytes;
+ MD5Bytes += S.MD5Bytes;
+ SHA1Bytes += S.SHA1Bytes;
SHA256Bytes += S.SHA256Bytes;
- Packages += S.Packages; Misses += S.Misses; DeLinkBytes += S.DeLinkBytes;};
+ SHA512Bytes += S.SHA512Bytes;
+ Packages += S.Packages;
+ Misses += S.Misses;
+ DeLinkBytes += S.DeLinkBytes;
+ };
Stats() : Bytes(0), MD5Bytes(0), SHA1Bytes(0), SHA256Bytes(0), Packages(0), Misses(0), DeLinkBytes(0) {};
} Stats;
@@ -125,7 +137,7 @@ class CacheDB
bool SetFile(string const &FileName,struct stat St,FileFd *Fd);
bool GetFileInfo(string const &FileName, bool const &DoControl, bool const &DoContents, bool const &GenContentsOnly,
- bool const &DoMD5, bool const &DoSHA1, bool const &DoSHA256, bool const &checkMtime = false);
+ bool const &DoMD5, bool const &DoSHA1, bool const &DoSHA256, bool const &DoSHA512, bool const &checkMtime = false);
bool Finish();
bool Clean();
diff --git a/ftparchive/contents.cc b/ftparchive/contents.cc
index b761d9204..eadced626 100644
--- a/ftparchive/contents.cc
+++ b/ftparchive/contents.cc
@@ -36,12 +36,13 @@
#include "contents.h"
#include <apti18n.h>
+#include <apt-pkg/debfile.h>
#include <apt-pkg/extracttar.h>
#include <apt-pkg/error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <malloc.h>
+#include <malloc.h>
/*}}}*/
// GenContents::~GenContents - Free allocated memory /*{{{*/
@@ -305,29 +306,7 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
bool ContentsExtract::Read(debDebFile &Deb)
{
Reset();
-
- // Get the archive member and positition the file
- const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz");
- const char *Compressor = "gzip";
- if (Member == 0) {
- Member = Deb.GotoMember("data.tar.bz2");
- Compressor = "bzip2";
- }
- if (Member == 0) {
- Member = Deb.GotoMember("data.tar.lzma");
- Compressor = "lzma";
- }
- if (Member == 0) {
- _error->Error(_("Internal error, could not locate member %s"),
- "data.tar.{gz,bz2,lzma}");
- return false;
- }
-
- // Extract it.
- ExtractTar Tar(Deb.GetFile(),Member->Size,Compressor);
- if (Tar.Go(*this) == false)
- return false;
- return true;
+ return Deb.ExtractArchive(*this);
}
/*}}}*/
// ContentsExtract::DoItem - Extract an item /*{{{*/
diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc
index bb4beedf9..f82879015 100644
--- a/ftparchive/multicompress.cc
+++ b/ftparchive/multicompress.cc
@@ -30,12 +30,6 @@
using namespace std;
-const MultiCompress::CompType MultiCompress::Compressors[] =
- {{".","",0,0,0,1},
- {"gzip",".gz","gzip","-9n","-d",2},
- {"bzip2",".bz2","bzip2","-9","-d",3},
- {"lzma",".lzma","lzma","-9","-d",4},
- {}};
// MultiCompress::MultiCompress - Constructor /*{{{*/
// ---------------------------------------------------------------------
@@ -48,7 +42,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
Outputter = -1;
Input = 0;
UpdateMTime = 0;
-
+
/* Parse the compression string, a space separated lists of compresison
types */
string::const_iterator I = Compress.begin();
@@ -61,13 +55,14 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
for (; I != Compress.end() && !isspace(*I); I++);
// Find the matching compressor
- const CompType *Comp = Compressors;
- for (; Comp->Name != 0; Comp++)
- if (stringcmp(Start,I,Comp->Name) == 0)
+ std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors();
+ std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin();
+ for (; Comp != Compressors.end(); ++Comp)
+ if (stringcmp(Start,I,Comp->Name.c_str()) == 0)
break;
// Hmm.. unknown.
- if (Comp->Name == 0)
+ if (Comp == Compressors.end())
{
_error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str());
continue;
@@ -77,7 +72,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress,
Files *NewOut = new Files;
NewOut->Next = Outputs;
Outputs = NewOut;
- NewOut->CompressProg = Comp;
+ NewOut->CompressProg = *Comp;
NewOut->Output = Output+Comp->Extension;
struct stat St;
@@ -141,13 +136,14 @@ bool MultiCompress::GetStat(string const &Output,string const &Compress,struct s
for (; I != Compress.end() && !isspace(*I); I++);
// Find the matching compressor
- const CompType *Comp = Compressors;
- for (; Comp->Name != 0; Comp++)
- if (stringcmp(Start,I,Comp->Name) == 0)
+ std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors();
+ std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin();
+ for (; Comp != Compressors.end(); ++Comp)
+ if (stringcmp(Start,I,Comp->Name.c_str()) == 0)
break;
// Hmm.. unknown.
- if (Comp->Name == 0)
+ if (Comp == Compressors.end())
continue;
string Name = Output+Comp->Extension;
@@ -268,13 +264,13 @@ bool MultiCompress::Finalize(unsigned long &OutSize)
/* This opens the compressor, either in compress mode or decompress
mode. FileFd is always the compressor input/output file,
OutFd is the created pipe, Input for Compress, Output for Decompress. */
-bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd,
- int &OutFd,bool const &Comp)
+bool MultiCompress::OpenCompress(APT::Configuration::Compressor const &Prog,
+ pid_t &Pid,int const &FileFd,int &OutFd,bool const &Comp)
{
Pid = -1;
// No compression
- if (Prog->Binary == 0)
+ if (Prog.Binary.empty() == true)
{
OutFd = dup(FileFd);
return true;
@@ -309,15 +305,17 @@ bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &File
SetCloseExec(STDOUT_FILENO,false);
SetCloseExec(STDIN_FILENO,false);
-
- const char *Args[3];
- Args[0] = Prog->Binary;
- if (Comp == true)
- Args[1] = Prog->CompArgs;
- else
- Args[1] = Prog->UnCompArgs;
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
+
+ std::vector<char const*> Args;
+ Args.push_back(Prog.Binary.c_str());
+ std::vector<std::string> const * const addArgs =
+ (Comp == true) ? &(Prog.CompressArgs) : &(Prog.UncompressArgs);
+ for (std::vector<std::string>::const_iterator a = addArgs->begin();
+ a != addArgs->end(); ++a)
+ Args.push_back(a->c_str());
+ Args.push_back(NULL);
+
+ execvp(Args[0],(char **)&Args[0]);
cerr << _("Failed to exec compressor ") << Args[0] << endl;
_exit(100);
};
@@ -335,7 +333,7 @@ bool MultiCompress::OpenOld(int &Fd,pid_t &Proc)
{
Files *Best = Outputs;
for (Files *I = Outputs; I != 0; I = I->Next)
- if (Best->CompressProg->Cost > I->CompressProg->Cost)
+ if (Best->CompressProg.Cost > I->CompressProg.Cost)
Best = I;
// Open the file
@@ -414,7 +412,7 @@ bool MultiCompress::Child(int const &FD)
for (Files *I = Outputs; I != 0; I = I->Next)
{
if (I->CompressProc != -1)
- ExecWait(I->CompressProc,I->CompressProg->Binary,false);
+ ExecWait(I->CompressProc, I->CompressProg.Binary.c_str(), false);
}
if (_error->PendingError() == true)
diff --git a/ftparchive/multicompress.h b/ftparchive/multicompress.h
index 3ac3b8fb2..19dede174 100644
--- a/ftparchive/multicompress.h
+++ b/ftparchive/multicompress.h
@@ -20,28 +20,18 @@
#include <string>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/aptconfiguration.h>
#include <stdio.h>
#include <sys/types.h>
class MultiCompress
{
- // Enumeration of all supported compressors
- struct CompType
- {
- const char *Name;
- const char *Extension;
- const char *Binary;
- const char *CompArgs;
- const char *UnCompArgs;
- unsigned char Cost;
- };
-
// An output file
struct Files
{
string Output;
- const CompType *CompressProg;
- Files *Next;
+ APT::Configuration::Compressor CompressProg;
+ Files *Next;
FileFd TmpFile;
pid_t CompressProc;
time_t OldMTime;
@@ -51,10 +41,9 @@ class MultiCompress
Files *Outputs;
pid_t Outputter;
mode_t Permissions;
- static const CompType Compressors[];
- bool OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd,
- int &OutFd,bool const &Comp);
+ bool OpenCompress(APT::Configuration::Compressor const &Prog,
+ pid_t &Pid,int const &FileFd, int &OutFd,bool const &Comp);
bool Child(int const &Fd);
bool Start();
bool Die();
diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc
index d7d699ddc..eb8938b95 100644
--- a/ftparchive/writer.cc
+++ b/ftparchive/writer.cc
@@ -17,9 +17,10 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/md5.h>
#include <apt-pkg/sha1.h>
-#include <apt-pkg/sha256.h>
+#include <apt-pkg/sha2.h>
#include <apt-pkg/deblistparser.h>
#include <sys/types.h>
@@ -59,6 +60,10 @@ FTWScanner::FTWScanner(string const &Arch): Arch(Arch)
{
ErrorPrinted = false;
NoLinkAct = !_config->FindB("APT::FTPArchive::DeLinkAct",true);
+
+ DoMD5 = _config->FindB("APT::FTPArchive::MD5",true);
+ DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true);
+ DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true);
}
/*}}}*/
// FTWScanner::Scanner - FTW Scanner /*{{{*/
@@ -306,11 +311,12 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c
Output = stdout;
SetExts(".deb .udeb");
DeLinkLimit = 0;
-
+
// Process the command line options
- DoMD5 = _config->FindB("APT::FTPArchive::MD5",true);
- DoSHA1 = _config->FindB("APT::FTPArchive::SHA1",true);
- DoSHA256 = _config->FindB("APT::FTPArchive::SHA256",true);
+ DoMD5 = _config->FindB("APT::FTPArchive::Packages::MD5",DoMD5);
+ DoSHA1 = _config->FindB("APT::FTPArchive::Packages::SHA1",DoSHA1);
+ DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA256",DoSHA256);
+ DoSHA256 = _config->FindB("APT::FTPArchive::Packages::SHA512",true);
DoAlwaysStat = _config->FindB("APT::FTPArchive::AlwaysStat", false);
DoContents = _config->FindB("APT::FTPArchive::Contents",true);
NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false);
@@ -365,7 +371,7 @@ bool FTWScanner::SetExts(string const &Vals)
bool PackagesWriter::DoPackage(string FileName)
{
// Pull all the data we need form the DB
- if (Db.GetFileInfo(FileName, true, DoContents, true, DoMD5, DoSHA1, DoSHA256, DoAlwaysStat)
+ if (Db.GetFileInfo(FileName, true, DoContents, true, DoMD5, DoSHA1, DoSHA256, DoSHA512, DoAlwaysStat)
== false)
{
return false;
@@ -435,9 +441,14 @@ bool PackagesWriter::DoPackage(string FileName)
unsigned int End = 0;
SetTFRewriteData(Changes[End++], "Size", Size);
- SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str());
- SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str());
- SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str());
+ if (DoMD5 == true)
+ SetTFRewriteData(Changes[End++], "MD5sum", Db.MD5Res.c_str());
+ if (DoSHA1 == true)
+ SetTFRewriteData(Changes[End++], "SHA1", Db.SHA1Res.c_str());
+ if (DoSHA256 == true)
+ SetTFRewriteData(Changes[End++], "SHA256", Db.SHA256Res.c_str());
+ if (DoSHA512 == true)
+ SetTFRewriteData(Changes[End++], "SHA512", Db.SHA512Res.c_str());
SetTFRewriteData(Changes[End++], "Filename", NewFileName.c_str());
SetTFRewriteData(Changes[End++], "Priority", OverItem->Priority.c_str());
SetTFRewriteData(Changes[End++], "Status", 0);
@@ -559,6 +570,9 @@ SourcesWriter::SourcesWriter(string const &BOverrides,string const &SOverrides,
BufSize = 0;
// Process the command line options
+ DoMD5 = _config->FindB("APT::FTPArchive::Sources::MD5",DoMD5);
+ DoSHA1 = _config->FindB("APT::FTPArchive::Sources::SHA1",DoSHA1);
+ DoSHA256 = _config->FindB("APT::FTPArchive::Sources::SHA256",DoSHA256);
NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false);
// Read the override file
@@ -608,13 +622,20 @@ bool SourcesWriter::DoPackage(string FileName)
// Hash the file
char *Start = Buffer;
char *BlkEnd = Buffer + St.st_size;
- MD5Summation MD5;
- MD5.Add((unsigned char *)Start,BlkEnd - Start);
+ MD5Summation MD5;
SHA1Summation SHA1;
SHA256Summation SHA256;
- SHA1.Add((unsigned char *)Start,BlkEnd - Start);
- SHA256.Add((unsigned char *)Start,BlkEnd - Start);
+ SHA256Summation SHA512;
+
+ if (DoMD5 == true)
+ MD5.Add((unsigned char *)Start,BlkEnd - Start);
+ if (DoSHA1 == true)
+ SHA1.Add((unsigned char *)Start,BlkEnd - Start);
+ if (DoSHA256 == true)
+ SHA256.Add((unsigned char *)Start,BlkEnd - Start);
+ if (DoSHA512 == true)
+ SHA512.Add((unsigned char *)Start,BlkEnd - Start);
// Add an extra \n to the end, just in case
*BlkEnd++ = '\n';
@@ -708,23 +729,29 @@ bool SourcesWriter::DoPackage(string FileName)
// Add the dsc to the files hash list
string const strippedName = flNotDir(FileName);
std::ostringstream ostreamFiles;
- if (Tags.Exists("Files"))
+ if (DoMD5 == true && Tags.Exists("Files"))
ostreamFiles << "\n " << string(MD5.Result()) << " " << St.st_size << " "
<< strippedName << "\n " << Tags.FindS("Files");
string const Files = ostreamFiles.str();
std::ostringstream ostreamSha1;
- if (Tags.Exists("Checksums-Sha1"))
+ if (DoSHA1 == true && Tags.Exists("Checksums-Sha1"))
ostreamSha1 << "\n " << string(SHA1.Result()) << " " << St.st_size << " "
<< strippedName << "\n " << Tags.FindS("Checksums-Sha1");
string const ChecksumsSha1 = ostreamSha1.str();
std::ostringstream ostreamSha256;
- if (Tags.Exists("Checksums-Sha256"))
+ if (DoSHA256 == true && Tags.Exists("Checksums-Sha256"))
ostreamSha256 << "\n " << string(SHA256.Result()) << " " << St.st_size << " "
<< strippedName << "\n " << Tags.FindS("Checksums-Sha256");
string const ChecksumsSha256 = ostreamSha256.str();
+ std::ostringstream ostreamSha512;
+ if (Tags.Exists("Checksums-Sha512"))
+ ostreamSha512 << "\n " << string(SHA512.Result()) << " " << St.st_size << " "
+ << strippedName << "\n " << Tags.FindS("Checksums-Sha512");
+ string const ChecksumsSha512 = ostreamSha512.str();
+
// Strip the DirStrip prefix from the FileName and add the PathPrefix
string NewFileName;
if (DirStrip.empty() == false &&
@@ -774,9 +801,14 @@ bool SourcesWriter::DoPackage(string FileName)
unsigned int End = 0;
SetTFRewriteData(Changes[End++],"Source",Package.c_str(),"Package");
- SetTFRewriteData(Changes[End++],"Files",Files.c_str());
- SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str());
- SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str());
+ if (Files.empty() == false)
+ SetTFRewriteData(Changes[End++],"Files",Files.c_str());
+ if (ChecksumsSha1.empty() == false)
+ SetTFRewriteData(Changes[End++],"Checksums-Sha1",ChecksumsSha1.c_str());
+ if (ChecksumsSha256.empty() == false)
+ SetTFRewriteData(Changes[End++],"Checksums-Sha256",ChecksumsSha256.c_str());
+ if (ChecksumsSha512.empty() == false)
+ SetTFRewriteData(Changes[End++],"Checksums-Sha512",ChecksumsSha512.c_str());
if (Directory != "./")
SetTFRewriteData(Changes[End++],"Directory",Directory.c_str());
SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str());
@@ -907,19 +939,29 @@ bool ContentsWriter::ReadFromPkgs(string const &PkgFile,string const &PkgCompres
/* */
ReleaseWriter::ReleaseWriter(string const &DB)
{
- AddPattern("Packages");
- AddPattern("Packages.gz");
- AddPattern("Packages.bz2");
- AddPattern("Packages.lzma");
- AddPattern("Sources");
- AddPattern("Sources.gz");
- AddPattern("Sources.bz2");
- AddPattern("Sources.lzma");
- AddPattern("Release");
- AddPattern("md5sum.txt");
+ if (_config->FindB("APT::FTPArchive::Release::Default-Patterns", true) == true)
+ {
+ AddPattern("Packages");
+ AddPattern("Packages.gz");
+ AddPattern("Packages.bz2");
+ AddPattern("Packages.lzma");
+ AddPattern("Packages.xz");
+ AddPattern("Sources");
+ AddPattern("Sources.gz");
+ AddPattern("Sources.bz2");
+ AddPattern("Sources.lzma");
+ AddPattern("Sources.xz");
+ AddPattern("Release");
+ AddPattern("Index");
+ AddPattern("md5sum.txt");
+ }
+ AddPatterns(_config->FindVector("APT::FTPArchive::Release::Patterns"));
Output = stdout;
time_t const now = time(NULL);
+
+ setlocale(LC_TIME, "C");
+
char datestr[128];
if (strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S UTC",
gmtime(&now)) == 0)
@@ -936,6 +978,8 @@ ReleaseWriter::ReleaseWriter(string const &DB)
validstr[0] = '\0';
}
+ setlocale(LC_TIME, "");
+
map<string,string> Fields;
Fields["Origin"] = "";
Fields["Label"] = "";
@@ -959,6 +1003,10 @@ ReleaseWriter::ReleaseWriter(string const &DB)
fprintf(Output, "%s: %s\n", (*I).first.c_str(), Value.c_str());
}
+
+ DoMD5 = _config->FindB("APT::FTPArchive::Release::MD5",DoMD5);
+ DoSHA1 = _config->FindB("APT::FTPArchive::Release::SHA1",DoSHA1);
+ DoSHA256 = _config->FindB("APT::FTPArchive::Release::SHA256",DoSHA256);
}
/*}}}*/
// ReleaseWriter::DoPackage - Process a single package /*{{{*/
@@ -991,19 +1039,30 @@ bool ReleaseWriter::DoPackage(string FileName)
CheckSums[NewFileName].size = fd.Size();
- MD5Summation MD5;
- MD5.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].MD5 = MD5.Result();
-
- fd.Seek(0);
- SHA1Summation SHA1;
- SHA1.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].SHA1 = SHA1.Result();
+ if (DoMD5 == true)
+ {
+ MD5Summation MD5;
+ MD5.AddFD(fd.Fd(), fd.Size());
+ CheckSums[NewFileName].MD5 = MD5.Result();
+ fd.Seek(0);
+ }
+ if (DoSHA1 == true)
+ {
+ SHA1Summation SHA1;
+ SHA1.AddFD(fd.Fd(), fd.Size());
+ CheckSums[NewFileName].SHA1 = SHA1.Result();
+ fd.Seek(0);
+ }
+ if (DoSHA256 == true)
+ {
+ SHA256Summation SHA256;
+ SHA256.AddFD(fd.Fd(), fd.Size());
+ CheckSums[NewFileName].SHA256 = SHA256.Result();
+ }
- fd.Seek(0);
- SHA256Summation SHA256;
+ SHA256Summation SHA512;
SHA256.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].SHA256 = SHA256.Result();
+ CheckSums[NewFileName].SHA512 = SHA512.Result();
fd.Close();
@@ -1015,37 +1074,52 @@ bool ReleaseWriter::DoPackage(string FileName)
// ---------------------------------------------------------------------
void ReleaseWriter::Finish()
{
- fprintf(Output, "MD5Sum:\n");
- for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
- I != CheckSums.end();
- ++I)
+ if (DoMD5 == true)
{
- fprintf(Output, " %s %16ld %s\n",
- (*I).second.MD5.c_str(),
- (*I).second.size,
- (*I).first.c_str());
+ fprintf(Output, "MD5Sum:\n");
+ for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+ I != CheckSums.end(); ++I)
+ {
+ fprintf(Output, " %s %16ld %s\n",
+ (*I).second.MD5.c_str(),
+ (*I).second.size,
+ (*I).first.c_str());
+ }
}
-
- fprintf(Output, "SHA1:\n");
- for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
- I != CheckSums.end();
- ++I)
+ if (DoSHA1 == true)
{
- fprintf(Output, " %s %16ld %s\n",
- (*I).second.SHA1.c_str(),
- (*I).second.size,
- (*I).first.c_str());
+ fprintf(Output, "SHA1:\n");
+ for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+ I != CheckSums.end(); ++I)
+ {
+ fprintf(Output, " %s %16ld %s\n",
+ (*I).second.SHA1.c_str(),
+ (*I).second.size,
+ (*I).first.c_str());
+ }
+ }
+ if (DoSHA256 == true)
+ {
+ fprintf(Output, "SHA256:\n");
+ for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
+ I != CheckSums.end(); ++I)
+ {
+ fprintf(Output, " %s %16ld %s\n",
+ (*I).second.SHA256.c_str(),
+ (*I).second.size,
+ (*I).first.c_str());
+ }
}
- fprintf(Output, "SHA256:\n");
+ fprintf(Output, "SHA512:\n");
for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
I != CheckSums.end();
++I)
{
- fprintf(Output, " %s %16ld %s\n",
- (*I).second.SHA256.c_str(),
+ fprintf(Output, " %s %32ld %s\n",
+ (*I).second.SHA512.c_str(),
(*I).second.size,
(*I).first.c_str());
}
-}
+}
diff --git a/ftparchive/writer.h b/ftparchive/writer.h
index 49d430c47..b8747decd 100644
--- a/ftparchive/writer.h
+++ b/ftparchive/writer.h
@@ -60,6 +60,9 @@ class FTWScanner
}
public:
+ bool DoMD5;
+ bool DoSHA1;
+ bool DoSHA256;
unsigned long DeLinkLimit;
string InternalPrefix;
@@ -69,6 +72,8 @@ class FTWScanner
bool LoadFileList(string const &BaseDir,string const &File);
void ClearPatterns() { Patterns.clear(); };
void AddPattern(string const &Pattern) { Patterns.push_back(Pattern); };
+ void AddPattern(char const *Pattern) { Patterns.push_back(Pattern); };
+ void AddPatterns(std::vector<std::string> const &patterns) { Patterns.insert(Patterns.end(), patterns.begin(), patterns.end()); };
bool SetExts(string const &Vals);
FTWScanner(string const &Arch = string());
@@ -101,9 +106,6 @@ class PackagesWriter : public FTWScanner
public:
// Some flags
- bool DoMD5;
- bool DoSHA1;
- bool DoSHA256;
bool DoAlwaysStat;
bool NoOverride;
bool DoContents;
@@ -193,6 +195,7 @@ protected:
string MD5;
string SHA1;
string SHA256;
+ string SHA512;
// Limited by FileFd::Size()
unsigned long size;
~CheckSum() {};