summaryrefslogtreecommitdiff
path: root/ftparchive
diff options
context:
space:
mode:
Diffstat (limited to 'ftparchive')
-rw-r--r--ftparchive/apt-ftparchive.cc2
-rw-r--r--ftparchive/writer.cc179
-rw-r--r--ftparchive/writer.h8
3 files changed, 117 insertions, 72 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/writer.cc b/ftparchive/writer.cc
index 086c44390..9462ebe27 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 /*{{{*/
@@ -306,11 +310,11 @@ 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);
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());
@@ -907,21 +924,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("Packages.xz");
- AddPattern("Sources");
- AddPattern("Sources.gz");
- AddPattern("Sources.bz2");
- AddPattern("Sources.lzma");
- AddPattern("Sources.xz");
- 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)
@@ -938,6 +963,8 @@ ReleaseWriter::ReleaseWriter(string const &DB)
validstr[0] = '\0';
}
+ setlocale(LC_TIME, "");
+
map<string,string> Fields;
Fields["Origin"] = "";
Fields["Label"] = "";
@@ -961,6 +988,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 /*{{{*/
@@ -993,19 +1024,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();
@@ -1017,37 +1055,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 49d430c47..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;
@@ -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;