]> git.saurik.com Git - apt.git/blobdiff - ftparchive/apt-ftparchive.cc
keep Release.gpg on untrusted to trusted IMS-Hit
[apt.git] / ftparchive / apt-ftparchive.cc
index ca03080ca221c584119220accb9a5f660000666b..ab6f48d616424b403ba11eed4ce2db0bf5fbff63 100644 (file)
@@ -68,6 +68,7 @@ struct PackageMap
 
    // We generate for this given arch
    string Arch;
 
    // We generate for this given arch
    string Arch;
+   bool IncludeArchAll;
    
    // Stuff for the Source File
    string SrcFile;
    
    // Stuff for the Source File
    string SrcFile;
@@ -122,9 +123,9 @@ struct PackageMap
                    vector<PackageMap>::iterator End,
                    unsigned long &Left);
    
                    vector<PackageMap>::iterator End,
                    unsigned long &Left);
    
-   PackageMap() : LongDesc(true), TransWriter(NULL), DeLinkLimit(0), Permissions(1),
-                 ContentsDone(false), PkgDone(false), SrcDone(false),
-                 ContentsMTime(0) {};
+   PackageMap() : IncludeArchAll(true), LongDesc(true), TransWriter(NULL),
+                 DeLinkLimit(0), Permissions(1), ContentsDone(false),
+                 PkgDone(false), SrcDone(false), ContentsMTime(0) {};
 };
                                                                        /*}}}*/
 
 };
                                                                        /*}}}*/
 
@@ -184,7 +185,7 @@ bool PackageMap::GenPackages(Configuration &Setup,struct CacheDB::Stats &Stats)
    PackagesWriter Packages(&Comp.Input, TransWriter, flCombine(CacheDir,BinCacheDB),
                           flCombine(OverrideDir,BinOverride),
                           flCombine(OverrideDir,ExtraOverride),
    PackagesWriter Packages(&Comp.Input, TransWriter, flCombine(CacheDir,BinCacheDB),
                           flCombine(OverrideDir,BinOverride),
                           flCombine(OverrideDir,ExtraOverride),
-                          Arch);
+                          Arch, IncludeArchAll);
    if (PkgExt.empty() == false && Packages.SetExts(PkgExt) == false)
       return _error->Error(_("Package extension list is too long"));
    if (_error->PendingError() == true)
    if (PkgExt.empty() == false && Packages.SetExts(PkgExt) == false)
       return _error->Error(_("Package extension list is too long"));
    if (_error->PendingError() == true)
@@ -364,7 +365,7 @@ bool PackageMap::GenContents(Configuration &Setup,
    MultiCompress Comp(flCombine(ArchiveDir,this->Contents),
                      CntCompress,Permissions);
    Comp.UpdateMTime = Setup.FindI("Default::ContentsAge",10)*24*60*60;
    MultiCompress Comp(flCombine(ArchiveDir,this->Contents),
                      CntCompress,Permissions);
    Comp.UpdateMTime = Setup.FindI("Default::ContentsAge",10)*24*60*60;
-   ContentsWriter Contents(&Comp.Input, "", Arch);
+   ContentsWriter Contents(&Comp.Input, "", Arch, IncludeArchAll);
    if (PkgExt.empty() == false && Contents.SetExts(PkgExt) == false)
       return _error->Error(_("Package extension list is too long"));
    if (_error->PendingError() == true)
    if (PkgExt.empty() == false && Contents.SetExts(PkgExt) == false)
       return _error->Error(_("Package extension list is too long"));
    if (_error->PendingError() == true)
@@ -487,6 +488,8 @@ static void LoadTree(vector<PackageMap> &PkgList, std::vector<TranslationWriter*
    bool const LongDescription = Setup.FindB("Default::LongDescription",
                                        _config->FindB("APT::FTPArchive::LongDescription", true));
    string const TranslationCompress = Setup.Find("Default::Translation::Compress",". gzip").c_str();
    bool const LongDescription = Setup.FindB("Default::LongDescription",
                                        _config->FindB("APT::FTPArchive::LongDescription", true));
    string const TranslationCompress = Setup.Find("Default::Translation::Compress",". gzip").c_str();
+   bool const ConfIncludeArchAllExists = _config->Exists("APT::FTPArchive::IncludeArchitectureAll");
+   bool const ConfIncludeArchAll = _config->FindB("APT::FTPArchive::IncludeArchitectureAll", true);
 
    // Process 'tree' type sections
    const Configuration::Item *Top = Setup.Tree("tree");
 
    // Process 'tree' type sections
    const Configuration::Item *Top = Setup.Tree("tree");
@@ -501,25 +504,32 @@ static void LoadTree(vector<PackageMap> &PkgList, std::vector<TranslationWriter*
       string Section;
       while (ParseQuoteWord(Sections,Section) == true)
       {
       string Section;
       while (ParseQuoteWord(Sections,Section) == true)
       {
-        string Arch;
-        struct SubstVar const Vars[] = {{"$(DIST)",&Dist},
+        struct SubstVar Vars[] = {{"$(DIST)",&Dist},
                                         {"$(SECTION)",&Section},
                                         {"$(SECTION)",&Section},
-                                        {"$(ARCH)",&Arch},
-                                        {NULL, NULL}};
+                                        {"$(ARCH)",nullptr},
+                                        {nullptr, nullptr}};
         mode_t const Perms = Block.FindI("FileMode", Permissions);
         bool const LongDesc = Block.FindB("LongDescription", LongDescription);
         mode_t const Perms = Block.FindI("FileMode", Permissions);
         bool const LongDesc = Block.FindB("LongDescription", LongDescription);
-        TranslationWriter *TransWriter = NULL;
-
-        string const Tmp2 = Block.Find("Architectures");
-        const char *Archs = Tmp2.c_str();
-        while (ParseQuoteWord(Archs,Arch) == true)
+        TranslationWriter *TransWriter = nullptr;
+
+        std::string Tmp2 = Block.Find("Architectures");
+        std::transform(Tmp2.begin(), Tmp2.end(), Tmp2.begin(), ::tolower);
+        std::vector<std::string> const Archs = VectorizeString(Tmp2, ' ');
+        bool IncludeArchAll;
+        if (ConfIncludeArchAllExists == true)
+           IncludeArchAll = ConfIncludeArchAll;
+        else
+           IncludeArchAll = std::find(Archs.begin(), Archs.end(), "all") == Archs.end();
+        for (auto const& Arch: Archs)
         {
         {
+           if (Arch.empty()) continue;
+           Vars[2].Contents = &Arch;
            PackageMap Itm;
            Itm.Permissions = Perms;
            Itm.BinOverride = SubstVar(Block.Find("BinOverride"),Vars);
            Itm.InternalPrefix = SubstVar(Block.Find("InternalPrefix",DIPrfx.c_str()),Vars);
 
            PackageMap Itm;
            Itm.Permissions = Perms;
            Itm.BinOverride = SubstVar(Block.Find("BinOverride"),Vars);
            Itm.InternalPrefix = SubstVar(Block.Find("InternalPrefix",DIPrfx.c_str()),Vars);
 
-           if (stringcasecmp(Arch,"source") == 0)
+           if (Arch == "source")
            {
               Itm.SrcOverride = SubstVar(Block.Find("SrcOverride"),Vars);
               Itm.BaseDir = SubstVar(Block.Find("SrcDirectory",DSDir.c_str()),Vars);
            {
               Itm.SrcOverride = SubstVar(Block.Find("SrcOverride"),Vars);
               Itm.BaseDir = SubstVar(Block.Find("SrcDirectory",DSDir.c_str()),Vars);
@@ -536,6 +546,7 @@ static void LoadTree(vector<PackageMap> &PkgList, std::vector<TranslationWriter*
               Itm.PkgFile = SubstVar(Block.Find("Packages",DPkg.c_str()),Vars);
               Itm.Tag = SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars);
               Itm.Arch = Arch;
               Itm.PkgFile = SubstVar(Block.Find("Packages",DPkg.c_str()),Vars);
               Itm.Tag = SubstVar("$(DIST)/$(SECTION)/$(ARCH)",Vars);
               Itm.Arch = Arch;
+              Itm.IncludeArchAll = IncludeArchAll;
               Itm.LongDesc = LongDesc;
               if (TransWriter == NULL && DTrans.empty() == false && LongDesc == false && DTrans != "/dev/null")
               {
               Itm.LongDesc = LongDesc;
               if (TransWriter == NULL && DTrans.empty() == false && LongDesc == false && DTrans != "/dev/null")
               {
@@ -604,16 +615,9 @@ static void LoadBinDir(vector<PackageMap> &PkgList,Configuration &Setup)
 }
                                                                        /*}}}*/
 
 }
                                                                        /*}}}*/
 
-// ShowHelp - Show the help text                                       /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
+static bool ShowHelp(CommandLine &)                                    /*{{{*/
 {
 {
-   ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-   if (_config->FindB("version") == true)
-      return true;
-
-   cout << 
+   std::cout <<
     _("Usage: apt-ftparchive [options] command\n"
       "Commands: packages binarypath [overridefile [pathprefix]]\n"
       "          sources srcpath [overridefile [pathprefix]]\n"
     _("Usage: apt-ftparchive [options] command\n"
       "Commands: packages binarypath [overridefile [pathprefix]]\n"
       "          sources srcpath [overridefile [pathprefix]]\n"
@@ -652,7 +656,6 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
       "  --contents  Control contents file generation\n"
       "  -c=?  Read this configuration file\n"
       "  -o=?  Set an arbitrary configuration option") << endl;
       "  --contents  Control contents file generation\n"
       "  -c=?  Read this configuration file\n"
       "  -o=?  Set an arbitrary configuration option") << endl;
-   
    return true;
 }
                                                                        /*}}}*/
    return true;
 }
                                                                        /*}}}*/
@@ -662,7 +665,7 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
 static bool SimpleGenPackages(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
 static bool SimpleGenPackages(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
-      return ShowHelp(CmdL, nullptr);
+      return ShowHelp(CmdL);
    
    string Override;
    if (CmdL.FileSize() >= 3)
    
    string Override;
    if (CmdL.FileSize() >= 3)
@@ -670,7 +673,8 @@ static bool SimpleGenPackages(CommandLine &CmdL)
    
    // Create a package writer object.
    PackagesWriter Packages(NULL, NULL, _config->Find("APT::FTPArchive::DB"),
    
    // Create a package writer object.
    PackagesWriter Packages(NULL, NULL, _config->Find("APT::FTPArchive::DB"),
-                          Override, "", _config->Find("APT::FTPArchive::Architecture"));
+                          Override, "", _config->Find("APT::FTPArchive::Architecture"),
+                          _config->FindB("APT::FTPArchive::IncludeArchitectureAll", true));
    if (_error->PendingError() == true)
       return false;
    
    if (_error->PendingError() == true)
       return false;
    
@@ -694,7 +698,7 @@ static bool SimpleGenPackages(CommandLine &CmdL)
 static bool SimpleGenContents(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
 static bool SimpleGenContents(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
-      return ShowHelp(CmdL, nullptr);
+      return ShowHelp(CmdL);
    
    // Create a package writer object.
    ContentsWriter Contents(NULL, _config->Find("APT::FTPArchive::DB"), _config->Find("APT::FTPArchive::Architecture"));
    
    // Create a package writer object.
    ContentsWriter Contents(NULL, _config->Find("APT::FTPArchive::DB"), _config->Find("APT::FTPArchive::Architecture"));
@@ -716,7 +720,7 @@ static bool SimpleGenContents(CommandLine &CmdL)
 static bool SimpleGenSources(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
 static bool SimpleGenSources(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
-      return ShowHelp(CmdL, nullptr);
+      return ShowHelp(CmdL);
    
    string Override;
    if (CmdL.FileSize() >= 3)
    
    string Override;
    if (CmdL.FileSize() >= 3)
@@ -753,7 +757,7 @@ static bool SimpleGenSources(CommandLine &CmdL)
 static bool SimpleGenRelease(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
 static bool SimpleGenRelease(CommandLine &CmdL)
 {
    if (CmdL.FileSize() < 2)
-      return ShowHelp(CmdL, nullptr);
+      return ShowHelp(CmdL);
 
    string Dir = CmdL.FileList[1];
 
 
    string Dir = CmdL.FileList[1];
 
@@ -815,12 +819,12 @@ static bool DoGeneratePackagesAndSources(Configuration &Setup,
       _error->DumpErrors();
       
       // Do the generation for Packages
       _error->DumpErrors();
       
       // Do the generation for Packages
-      for (End = List; End->Str != 0; End++)
+      for (End = List; End->Str != 0; ++End)
       {
         if (End->Hit == false)
            continue;
         
       {
         if (End->Hit == false)
            continue;
         
-        PackageMap *I = (PackageMap *)End->UserData;
+        PackageMap * const I = static_cast<PackageMap *>(End->UserData);
         if (I->PkgDone == true)
            continue;
         if (I->GenPackages(Setup,Stats) == false)
         if (I->PkgDone == true)
            continue;
         if (I->GenPackages(Setup,Stats) == false)
@@ -828,12 +832,12 @@ static bool DoGeneratePackagesAndSources(Configuration &Setup,
       }
       
       // Do the generation for Sources
       }
       
       // Do the generation for Sources
-      for (End = List; End->Str != 0; End++)
+      for (End = List; End->Str != 0; ++End)
       {
         if (End->Hit == false)
            continue;
         
       {
         if (End->Hit == false)
            continue;
         
-        PackageMap *I = (PackageMap *)End->UserData;
+        PackageMap * const I = static_cast<PackageMap *>(End->UserData);
         if (I->SrcDone == true)
            continue;
         if (I->GenSources(Setup,SrcStats) == false)
         if (I->SrcDone == true)
            continue;
         if (I->GenSources(Setup,SrcStats) == false)
@@ -921,7 +925,7 @@ static bool Generate(CommandLine &CmdL)
 {
    struct CacheDB::Stats SrcStats;
    if (CmdL.FileSize() < 2)
 {
    struct CacheDB::Stats SrcStats;
    if (CmdL.FileSize() < 2)
-      return ShowHelp(CmdL, nullptr);
+      return ShowHelp(CmdL);
 
    struct timeval StartTime;
    gettimeofday(&StartTime,0);
 
    struct timeval StartTime;
    gettimeofday(&StartTime,0);
@@ -979,7 +983,7 @@ static bool Generate(CommandLine &CmdL)
 static bool Clean(CommandLine &CmdL)
 {
    if (CmdL.FileSize() != 2)
 static bool Clean(CommandLine &CmdL)
 {
    if (CmdL.FileSize() != 2)
-      return ShowHelp(CmdL, nullptr);
+      return ShowHelp(CmdL);
 
    // Read the configuration file.
    Configuration Setup;
 
    // Read the configuration file.
    Configuration Setup;
@@ -1025,11 +1029,9 @@ static bool Clean(CommandLine &CmdL)
 }
                                                                        /*}}}*/
 
 }
                                                                        /*}}}*/
 
-int main(int argc, const char *argv[])
+static std::vector<aptDispatchWithHelp> GetCommands()                  /*{{{*/
 {
 {
-   InitLocale();
-
-   CommandLine::DispatchWithHelp Cmds[] = {
+   return {
       {"packages",&SimpleGenPackages, nullptr},
       {"contents",&SimpleGenContents, nullptr},
       {"sources",&SimpleGenSources, nullptr},
       {"packages",&SimpleGenPackages, nullptr},
       {"contents",&SimpleGenContents, nullptr},
       {"sources",&SimpleGenSources, nullptr},
@@ -1038,10 +1040,13 @@ int main(int argc, const char *argv[])
       {"clean",&Clean, nullptr},
       {nullptr, nullptr, nullptr}
    };
       {"clean",&Clean, nullptr},
       {nullptr, nullptr, nullptr}
    };
-
+}
+                                                                       /*}}}*/
+int main(int argc, const char *argv[])                                 /*{{{*/
+{
    // Parse the command line and initialize the package library
    CommandLine CmdL;
    // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, "apt-ftparchive", &_config, NULL, argc, argv, ShowHelp);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_FTPARCHIVE, &_config, NULL, argc, argv, ShowHelp, &GetCommands);
 
    _config->CndSet("quiet",0);
    Quiet = _config->FindI("quiet",0);
 
    _config->CndSet("quiet",0);
    Quiet = _config->FindI("quiet",0);
@@ -1049,3 +1054,4 @@ int main(int argc, const char *argv[])
 
    return DispatchCommandLine(CmdL, Cmds);
 }
 
    return DispatchCommandLine(CmdL, Cmds);
 }
+                                                                       /*}}}*/