X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/989539655e3bb8e6934b5f69ece67c173a26c4f2..f8477782df203e1998a8704e71a1a3cc699e9e3a:/ftparchive/writer.cc?ds=inline diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 68fd85091..fc9ea27d7 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -1,6 +1,6 @@ // -*- 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 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,6 @@ #include "apt-ftparchive.h" #include "multicompress.h" /*}}}*/ - using namespace std; FTWScanner *FTWScanner::Owner; @@ -284,10 +284,12 @@ bool FTWScanner::Delink(string &FileName,const char *OriginalPath, // PackagesWriter::PackagesWriter - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -PackagesWriter::PackagesWriter(string DB,string Overrides,string ExtOverrides) : - Db(DB),Stats(Db.Stats) +PackagesWriter::PackagesWriter(string DB,string Overrides,string ExtOverrides, + string aArch) : + Db(DB),Stats(Db.Stats), Arch(aArch) { Output = stdout; + SetExts(".deb .udeb .foo .bar .baz"); AddPattern("*.deb"); DeLinkLimit = 0; @@ -318,15 +320,20 @@ bool FTWScanner::SetExts(string Vals) { 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; @@ -364,14 +371,22 @@ bool PackagesWriter::DoPackage(string FileName) // Lookup the overide information pkgTagSection &Tags = Db.Control.Section; string Package = Tags.FindS("Package"); - Override::Item Tmp; - Override::Item *OverItem = Over.GetItem(Package); + string Architecture; + // if we generate a Packages file for a given arch, we use it to + // look for overrides. if we run in "simple" mode without the + // "Architecures" variable in the config we use the architecure value + // from the deb file + if(Arch != "") + Architecture = Arch; + else + Architecture = Tags.FindS("Architecture"); + auto_ptr OverItem(Over.GetItem(Package,Architecture)); if (Package.empty() == true) return _error->Error(_("Archive had no package field")); - + // If we need to do any rewriting of the header do it now.. - if (OverItem == 0) + if (OverItem.get() == 0) { if (NoOverride == false) { @@ -379,9 +394,9 @@ bool PackagesWriter::DoPackage(string FileName) ioprintf(c1out, _(" %s has no override entry\n"), Package.c_str()); } - OverItem = &Tmp; - Tmp.FieldOverride["Section"] = Tags.FindS("Section"); - Tmp.Priority = Tags.FindS("Priority"); + OverItem = auto_ptr(new Override::Item); + OverItem->FieldOverride["Section"] = Tags.FindS("Section"); + OverItem->Priority = Tags.FindS("Priority"); } char Size[40]; @@ -548,10 +563,10 @@ bool SourcesWriter::DoPackage(string FileName) // Lookup the overide information, finding first the best priority. string BestPrio; - char Buffer[1000]; string Bins = Tags.FindS("Binary"); - Override::Item *OverItem = 0; - if (Bins.empty() == false && Bins.length() < sizeof(Buffer)) + char Buffer[Bins.length() + 1]; + auto_ptr OverItem(0); + if (Bins.empty() == false) { strcpy(Buffer,Bins.c_str()); @@ -563,11 +578,9 @@ bool SourcesWriter::DoPackage(string FileName) unsigned char BestPrioV = pkgCache::State::Extra; for (unsigned I = 0; BinList[I] != 0; I++) { - Override::Item *Itm = BOver.GetItem(BinList[I]); - if (Itm == 0) + auto_ptr Itm(BOver.GetItem(BinList[I])); + if (Itm.get() == 0) continue; - if (OverItem == 0) - OverItem = Itm; unsigned char NewPrioV = debListParser::GetPrio(Itm->Priority); if (NewPrioV < BestPrioV || BestPrio.empty() == true) @@ -575,12 +588,14 @@ bool SourcesWriter::DoPackage(string FileName) BestPrioV = NewPrioV; BestPrio = Itm->Priority; } + + if (OverItem.get() == 0) + OverItem = Itm; } } // If we need to do any rewriting of the header do it now.. - Override::Item Tmp; - if (OverItem == 0) + if (OverItem.get() == 0) { if (NoOverride == false) { @@ -588,15 +603,19 @@ bool SourcesWriter::DoPackage(string FileName) ioprintf(c1out, _(" %s has no override entry\n"), Tags.FindS("Source").c_str()); } - OverItem = &Tmp; + OverItem = auto_ptr(new Override::Item); } - Override::Item *SOverItem = SOver.GetItem(Tags.FindS("Source")); - if (SOverItem == 0) + auto_ptr SOverItem(SOver.GetItem(Tags.FindS("Source"))); + const auto_ptr autoSOverItem(SOverItem); + if (SOverItem.get() == 0) { - SOverItem = BOver.GetItem(Tags.FindS("Source")); - if (SOverItem == 0) - SOverItem = OverItem; + SOverItem = auto_ptr(BOver.GetItem(Tags.FindS("Source"))); + if (SOverItem.get() == 0) + { + SOverItem = auto_ptr(new Override::Item); + *SOverItem = *OverItem; + } } // Add the dsc to the files hash list @@ -747,7 +766,7 @@ bool ContentsWriter::ReadFromPkgs(string PkgFile,string PkgCompress) // Open the package file int CompFd = -1; - int Proc = -1; + pid_t Proc = -1; if (Pkgs.OpenOld(CompFd,Proc) == false) return false; @@ -798,6 +817,13 @@ ReleaseWriter::ReleaseWriter(string DB) { 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]; @@ -829,8 +855,6 @@ ReleaseWriter::ReleaseWriter(string DB) fprintf(Output, "%s: %s\n", (*I).first.c_str(), Value.c_str()); } - - fprintf(Output, "MD5Sum:\n"); } /*}}}*/ // ReleaseWriter::DoPackage - Process a single package /*{{{*/ @@ -843,9 +867,14 @@ bool ReleaseWriter::DoPackage(string FileName) 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); @@ -856,14 +885,47 @@ bool ReleaseWriter::DoPackage(string FileName) 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::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::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()); + } +} +