X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/c0eb6bc6c89ba41011b9e7ef2e94cdfa4c92e142..f8477782df203e1998a8704e71a1a3cc699e9e3a:/ftparchive/writer.cc diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index e495a4c45..fc9ea27d7 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: writer.cc,v 1.11 2004/01/02 21:48:13 mdz Exp $ +// $Id: writer.cc,v 1.14 2004/03/24 01:40:43 mdz Exp $ /* ###################################################################### Writer @@ -36,7 +36,6 @@ #include "apt-ftparchive.h" #include "multicompress.h" /*}}}*/ - using namespace std; FTWScanner *FTWScanner::Owner; @@ -285,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; @@ -319,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) + { + Length = Vals.length()-Start; + } + else { - AddPattern(string("*") + string(Start, space-1)); - Start = space + 1; + Length = Space-Start; } + AddPattern(string("*") + Vals.substr(Start, Length)); + Start += Length + 1; } return true; @@ -365,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) { @@ -380,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]; @@ -549,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()); @@ -564,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) @@ -576,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) { @@ -589,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 @@ -748,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; @@ -852,7 +870,7 @@ bool ReleaseWriter::DoPackage(string FileName) { NewFileName = string(FileName.begin() + DirStrip.length(),FileName.end()); while (NewFileName[0] == '/') - NewFileName = string(FileName.begin() + 1,FileName.end()); + NewFileName = string(NewFileName.begin() + 1,NewFileName.end()); } else NewFileName = FileName;