summaryrefslogtreecommitdiff
path: root/ftparchive/writer.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2011-02-22 14:49:16 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2011-02-22 14:49:16 +0100
commit3c54407f8783d5e27363eabf41dbc3d031526ffe (patch)
treeb00673fa625cce51ef322840ccf1aff2f57ac8fa /ftparchive/writer.cc
parentcb12d0a677b63b6faeaefeda475c466d66fed212 (diff)
add options to disable specific checksums for Indexes
Diffstat (limited to 'ftparchive/writer.cc')
-rw-r--r--ftparchive/writer.cc143
1 files changed, 87 insertions, 56 deletions
diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc
index 80ec61ab9..d3a19ca28 100644
--- a/ftparchive/writer.cc
+++ b/ftparchive/writer.cc
@@ -59,6 +59,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 /*{{{*/
@@ -308,9 +312,9 @@ PackagesWriter::PackagesWriter(string const &DB,string const &Overrides,string c
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);
DoAlwaysStat = _config->FindB("APT::FTPArchive::AlwaysStat", false);
DoContents = _config->FindB("APT::FTPArchive::Contents",true);
NoOverride = _config->FindB("APT::FTPArchive::NoOverrideMsg",false);
@@ -435,9 +439,12 @@ 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());
SetTFRewriteData(Changes[End++], "Filename", NewFileName.c_str());
SetTFRewriteData(Changes[End++], "Priority", OverItem->Priority.c_str());
SetTFRewriteData(Changes[End++], "Status", 0);
@@ -559,6 +566,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 +618,17 @@ 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);
+
+ 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);
// Add an extra \n to the end, just in case
*BlkEnd++ = '\n';
@@ -708,19 +722,19 @@ 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();
@@ -774,9 +788,12 @@ 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 (Directory != "./")
SetTFRewriteData(Changes[End++],"Directory",Directory.c_str());
SetTFRewriteData(Changes[End++],"Priority",BestPrio.c_str());
@@ -969,6 +986,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 /*{{{*/
@@ -1001,19 +1022,26 @@ 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();
-
- fd.Seek(0);
- SHA256Summation SHA256;
- SHA256.AddFD(fd.Fd(), fd.Size());
- CheckSums[NewFileName].SHA256 = SHA256.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.Close();
@@ -1025,37 +1053,40 @@ 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());
+ }
}
-
- fprintf(Output, "SHA256:\n");
- for(map<string,struct CheckSum>::const_iterator I = CheckSums.begin();
- I != CheckSums.end();
- ++I)
+ if (DoSHA256 == true)
{
- fprintf(Output, " %s %16ld %s\n",
- (*I).second.SHA256.c_str(),
- (*I).second.size,
- (*I).first.c_str());
+ 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());
+ }
}
}
-