// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: writer.cc,v 1.8 2003/12/26 20:08:56 mdz Exp $
+// $Id: writer.cc,v 1.14 2004/03/24 01:40:43 mdz Exp $
/* ######################################################################
Writer
#include <apt-pkg/error.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/md5.h>
+#include <apt-pkg/sha1.h>
#include <apt-pkg/deblistparser.h>
#include <sys/types.h>
Db(DB),Stats(Db.Stats)
{
Output = stdout;
+ SetExts(".deb .udeb .foo .bar .baz");
AddPattern("*.deb");
DeLinkLimit = 0;
{
ClearPatterns();
string::size_type Start = 0;
- for(string::size_type space = Vals.find(' ');
- space != string::npos;
- space = Vals.find(' ', space))
+ while (Start <= Vals.length()-1)
{
- if (space > 0)
+ string::size_type Space = Vals.find(' ',Start);
+ string::size_type Length;
+ if (Space == string::npos)
{
- AddPattern(string("*") + string(Start, space-1));
- Start = space + 1;
+ Length = Vals.length()-Start;
}
+ else
+ {
+ Length = Space-Start;
+ }
+ AddPattern(string("*") + Vals.substr(Start, Length));
+ Start += Length + 1;
}
return true;
// Lookup the overide information, finding first the best priority.
string BestPrio;
- char Buffer[1000];
string Bins = Tags.FindS("Binary");
+ char Buffer[Bins.length() + 1];
Override::Item *OverItem = 0;
- if (Bins.empty() == false && Bins.length() < sizeof(Buffer))
+ if (Bins.empty() == false)
{
strcpy(Buffer,Bins.c_str());
{
AddPattern("Packages");
AddPattern("Packages.gz");
+ AddPattern("Packages.bz2");
+ AddPattern("Sources");
+ AddPattern("Sources.gz");
+ AddPattern("Sources.bz2");
+ AddPattern("Release");
+ AddPattern("md5sum.txt");
+
Output = stdout;
time_t now = time(NULL);
char datestr[128];
fprintf(Output, "%s: %s\n", (*I).first.c_str(), Value.c_str());
}
-
- fprintf(Output, "MD5Sum:\n");
}
/*}}}*/
// ReleaseWriter::DoPackage - Process a single package /*{{{*/
FileName.length() > DirStrip.length() &&
stringcmp(FileName.begin(),FileName.begin() + DirStrip.length(),
DirStrip.begin(),DirStrip.end()) == 0)
+ {
NewFileName = string(FileName.begin() + DirStrip.length(),FileName.end());
+ while (NewFileName[0] == '/')
+ NewFileName = string(NewFileName.begin() + 1,NewFileName.end());
+ }
else
NewFileName = FileName;
+
if (PathPrefix.empty() == false)
NewFileName = flCombine(PathPrefix,NewFileName);
return false;
}
+ CheckSums[NewFileName].size = fd.Size();
+
MD5Summation MD5;
MD5.AddFD(fd.Fd(), fd.Size());
+ CheckSums[NewFileName].MD5 = MD5.Result();
- string MD5Sum = MD5.Result();
- fprintf(Output, " %s %16d %s\n",
- MD5Sum.c_str(), fd.Size(), FileName.c_str());
+ fd.Seek(0);
+ SHA1Summation SHA1;
+ SHA1.AddFD(fd.Fd(), fd.Size());
+ CheckSums[NewFileName].SHA1 = SHA1.Result();
fd.Close();
return true;
}
+
+ /*}}}*/
+// ReleaseWriter::Finish - Output the checksums /*{{{*/
+// ---------------------------------------------------------------------
+void ReleaseWriter::Finish()
+{
+ fprintf(Output, "MD5Sum:\n");
+ for(map<string,struct CheckSum>::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>::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());
+ }
+}
+