diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-02-22 14:49:16 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-02-22 14:49:16 +0100 |
commit | 3c54407f8783d5e27363eabf41dbc3d031526ffe (patch) | |
tree | b00673fa625cce51ef322840ccf1aff2f57ac8fa | |
parent | cb12d0a677b63b6faeaefeda475c466d66fed212 (diff) | |
download | apt-3c54407f8783d5e27363eabf41dbc3d031526ffe.tar.gz |
add options to disable specific checksums for Indexes
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | doc/apt-ftparchive.1.xml | 11 | ||||
-rw-r--r-- | ftparchive/apt-ftparchive.cc | 2 | ||||
-rw-r--r-- | ftparchive/writer.cc | 143 | ||||
-rw-r--r-- | ftparchive/writer.h | 6 |
5 files changed, 101 insertions, 65 deletions
diff --git a/debian/changelog b/debian/changelog index 4712e80c4..bbb973b8f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,3 @@ - apt (0.8.11.6) UNRELEASED; urgency=low [ Christian Perrier ] @@ -9,8 +8,9 @@ apt (0.8.11.6) UNRELEASED; urgency=low [ David Kalnischkies ] * ftparchive/writer.cc: - ensure that Date and Valid-Until time strings are not localised + - add options to disable specific checksums for Indexes - -- David Kalnischkies <kalnischkies@gmail.com> Tue, 22 Feb 2011 13:22:58 +0100 + -- David Kalnischkies <kalnischkies@gmail.com> Tue, 22 Feb 2011 14:48:21 +0100 apt (0.8.11.5) unstable; urgency=low diff --git a/doc/apt-ftparchive.1.xml b/doc/apt-ftparchive.1.xml index 0090d21d9..8e5df1f36 100644 --- a/doc/apt-ftparchive.1.xml +++ b/doc/apt-ftparchive.1.xml @@ -526,11 +526,14 @@ for i in Sections do &apt-cmdblurb; <variablelist> - <varlistentry><term><option>--md5</option></term> + <varlistentry><term><option>--md5</option>, <option>--sha1</option>, <option>--sha256</option></term> <listitem><para> - Generate MD5 sums. This defaults to on, when turned off the generated - index files will not have MD5Sum fields where possible. - Configuration Item: <literal>APT::FTPArchive::MD5</literal></para></listitem> + Generate the given checksum. These options default to on, when turned off the generated + index files will not have the checksum fields where possible. + Configuration Items: <literal>APT::FTPArchive::<replaceable>Checksum</replaceable></literal> and + <literal>APT::FTPArchive::<replaceable>Index</replaceable>::<replaceable>Checksum</replaceable></literal> where + <literal>Index</literal> can be <literal>Packages</literal>, <literal>Sources</literal> or <literal>Release</literal> and + <literal>Checksum</literal> can be <literal>MD5</literal>, <literal>SHA1</literal> or <literal>SHA256</literal>.</para></listitem> </varlistentry> <varlistentry><term><option>-d</option></term><term><option>--db</option></term> 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/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()); + } } } - diff --git a/ftparchive/writer.h b/ftparchive/writer.h index 3796f79f6..ce0eab7af 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; @@ -103,9 +106,6 @@ class PackagesWriter : public FTWScanner public: // Some flags - bool DoMD5; - bool DoSHA1; - bool DoSHA256; bool DoAlwaysStat; bool NoOverride; bool DoContents; |