]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/debindexfile.cc
rework dpkg-wrapping in test framework
[apt.git] / apt-pkg / deb / debindexfile.cc
index 3bdc551b40c7623f2ec504f5cd6867a78615ddf7..cecfe41a9d477759ba2df6cea8bee44e1ad1e89b 100644 (file)
@@ -81,14 +81,18 @@ pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
 {
    string SourcesURI = _config->FindDir("Dir::State::lists") + 
       URItoFileName(IndexURI("Sources"));
-   string SourcesURIgzip = SourcesURI + ".gz";
 
-   if (!FileExists(SourcesURI) && !FileExists(SourcesURIgzip))
-      return NULL;
-   else if (!FileExists(SourcesURI) && FileExists(SourcesURIgzip))
-      SourcesURI = SourcesURIgzip;
-
-   return new debSrcRecordParser(SourcesURI,this);
+   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+   {
+      string p;
+      p = SourcesURI + '.' + *t;
+      if (FileExists(p))
+         return new debSrcRecordParser(p, this);
+   }
+   if (FileExists(SourcesURI))
+      return new debSrcRecordParser(SourcesURI, this);
+   return NULL;
 }
                                                                        /*}}}*/
 // SourcesIndex::Describe - Give a descriptive path to the index       /*{{{*/
@@ -127,14 +131,18 @@ string debSourcesIndex::Info(const char *Type) const
 // SourcesIndex::Index* - Return the URI to the index files            /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-inline string debSourcesIndex::IndexFile(const char *Type) const
+string debSourcesIndex::IndexFile(const char *Type) const
 {
    string s = URItoFileName(IndexURI(Type));
-   string sgzip = s + ".gz";
-   if (!FileExists(s) && FileExists(sgzip))
-       return sgzip;
-   else
-       return s;
+
+   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+   {
+      string p = s + '.' + *t;
+      if (FileExists(p))
+         return p;
+   }
+   return s;
 }
 
 string debSourcesIndex::IndexURI(const char *Type) const
@@ -257,14 +265,18 @@ string debPackagesIndex::Info(const char *Type) const
 // PackagesIndex::Index* - Return the URI to the index files           /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-inline string debPackagesIndex::IndexFile(const char *Type) const
+string debPackagesIndex::IndexFile(const char *Type) const
 {
    string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
-   string sgzip = s + ".gz";
-   if (!FileExists(s) && FileExists(sgzip))
-       return sgzip;
-   else
-       return s;
+
+   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+   {
+      string p = s + '.' + *t;
+      if (FileExists(p))
+         return p;
+   }
+   return s;
 }
 string debPackagesIndex::IndexURI(const char *Type) const
 {
@@ -409,14 +421,18 @@ debTranslationsIndex::debTranslationsIndex(string URI,string Dist,string Section
 // TranslationIndex::Trans* - Return the URI to the translation files  /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-inline string debTranslationsIndex::IndexFile(const char *Type) const
+string debTranslationsIndex::IndexFile(const char *Type) const
 {
    string s =_config->FindDir("Dir::State::lists") + URItoFileName(IndexURI(Type));
-   string sgzip = s + ".gz";
-   if (!FileExists(s) && FileExists(sgzip))
-       return sgzip;
-   else
-       return s;
+
+   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+   for (std::vector<std::string>::const_iterator t = types.begin(); t != types.end(); ++t)
+   {
+      string p = s + '.' + *t;
+      if (FileExists(p))
+         return p;
+   }
+   return s;
 }
 string debTranslationsIndex::IndexURI(const char *Type) const
 {
@@ -436,19 +452,6 @@ string debTranslationsIndex::IndexURI(const char *Type) const
    return Res;
 }
                                                                        /*}}}*/
-// TranslationsIndex::GetIndexes - Fetch the index files               /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-bool debTranslationsIndex::GetIndexes(pkgAcquire *Owner) const
-{
-   string const TranslationFile = string("Translation-").append(Language);
-   new pkgAcqIndexTrans(Owner, IndexURI(Language),
-                        Info(TranslationFile.c_str()),
-                        TranslationFile);
-
-   return true;
-}
-                                                                       /*}}}*/
 // TranslationsIndex::Describe - Give a descriptive path to the index  /*{{{*/
 // ---------------------------------------------------------------------
 /* This should help the user find the index in the sources.list and
@@ -619,7 +622,7 @@ bool debStatusIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
    pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
    CFile->Size = Pkg.FileSize();
    CFile->mtime = Pkg.ModificationTime();
-   map_ptrloc const storage = Gen.WriteUniqString("now");
+   map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::MIXED, "now");
    CFile->Archive = storage;
    
    if (Gen.MergeList(Parser) == false)
@@ -692,15 +695,27 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const
 
    // get the control data out of the deb file vid dpkg -I
    // ... can I haz libdpkg?
+   Configuration::Item const *Opts = _config->Tree("DPkg::Options");
    std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg");
-   const char *Args[5] = {dpkg.c_str(),
-                          "-I",
-                          DebFile.c_str(),
-                          "control",
-                          NULL};
+   std::vector<const char *> Args;
+   Args.push_back(dpkg.c_str());
+   if (Opts != 0)
+   {
+      Opts = Opts->Child;
+      for (; Opts != 0; Opts = Opts->Next)
+      {
+        if (Opts->Value.empty() == true)
+           continue;
+        Args.push_back(Opts->Value.c_str());
+      }
+   }
+   Args.push_back("-I");
+   Args.push_back(DebFile.c_str());
+   Args.push_back("control");
+   Args.push_back(NULL);
    FileFd PipeFd;
    pid_t Child;
-   if(Popen(Args, PipeFd, Child, FileFd::ReadOnly) == false)
+   if(Popen((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
       return _error->Error("Popen failed");
    // FIXME: static buffer
    char buf[8*1024];
@@ -710,7 +725,7 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const
    ExecWait(Child, "Popen");
 
    // now write the control data to a tempfile
-   SPtr<FileFd> DebControl = GetTempFile("deb-file-" + DebFile);
+   SPtr<FileFd> DebControl = GetTempFile("deb-file-" + flNotDir(DebFile));
    if(DebControl == NULL)
       return false;
    DebControl->Write(buf, n);
@@ -738,8 +753,6 @@ bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const
 }
 pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const
 {
-   // FIXME: we could simply always return pkgCache::PkgFileIterator(Cache);
-   //        to indicate its never in the cache which will force a Merge()
    pkgCache::PkgFileIterator File = Cache.FileBegin();
    for (; File.end() == false; ++File)
    {
@@ -780,8 +793,6 @@ unsigned long debDscFileIndex::Size() const
 }
 
 // DscFileIndex::CreateSrcParser - Get a parser for the .dsc file      /*{{{*/
-// ---------------------------------------------------------------------
-/* */
 pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
 {
    if (!FileExists(DscFile))
@@ -790,19 +801,14 @@ pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
    return new debDscRecordParser(DscFile,this);
 }
                                                                        /*}}}*/
-
-
-
-
-// ---------------------------------------------------------------------
 // Index File types for Debian                                         /*{{{*/
-class debIFTypeSrc : public pkgIndexFile::Type
+class APT_HIDDEN debIFTypeSrc : public pkgIndexFile::Type
 {
    public:
    
    debIFTypeSrc() {Label = "Debian Source Index";};
 };
-class debIFTypePkg : public pkgIndexFile::Type
+class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type
 {
    public:
    
@@ -812,12 +818,12 @@ class debIFTypePkg : public pkgIndexFile::Type
    };
    debIFTypePkg() {Label = "Debian Package Index";};
 };
-class debIFTypeTrans : public debIFTypePkg
+class APT_HIDDEN debIFTypeTrans : public debIFTypePkg
 {
    public:
    debIFTypeTrans() {Label = "Debian Translation Index";};
 };
-class debIFTypeStatus : public pkgIndexFile::Type
+class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type
 {
    public:
    
@@ -827,7 +833,7 @@ class debIFTypeStatus : public pkgIndexFile::Type
    };
    debIFTypeStatus() {Label = "Debian dpkg status file";};
 };
-class debIFTypeDebPkgFile : public pkgIndexFile::Type
+class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type
 {
    public:
    virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const 
@@ -836,7 +842,7 @@ class debIFTypeDebPkgFile : public pkgIndexFile::Type
    };
    debIFTypeDebPkgFile() {Label = "deb Package file";};
 };
-class debIFTypeDscFile : public pkgIndexFile::Type
+class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type
 {
    public:
    virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const
@@ -845,7 +851,7 @@ class debIFTypeDscFile : public pkgIndexFile::Type
    };
    debIFTypeDscFile() {Label = "dsc File Source Index";};
 };
-class debIFTypeDebianSourceDir : public pkgIndexFile::Type
+class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type
 {
    public:
    virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const
@@ -855,14 +861,14 @@ class debIFTypeDebianSourceDir : public pkgIndexFile::Type
    debIFTypeDebianSourceDir() {Label = "debian/control File Source Index";};
 };
 
-static debIFTypeSrc _apt_Src;
-static debIFTypePkg _apt_Pkg;
-static debIFTypeTrans _apt_Trans;
-static debIFTypeStatus _apt_Status;
-static debIFTypeDebPkgFile _apt_DebPkgFile;
+APT_HIDDEN debIFTypeSrc _apt_Src;
+APT_HIDDEN debIFTypePkg _apt_Pkg;
+APT_HIDDEN debIFTypeTrans _apt_Trans;
+APT_HIDDEN debIFTypeStatus _apt_Status;
+APT_HIDDEN debIFTypeDebPkgFile _apt_DebPkgFile;
 // file based pseudo indexes
-static debIFTypeDscFile _apt_DscFile;
-static debIFTypeDebianSourceDir _apt_DebianSourceDir;
+APT_HIDDEN debIFTypeDscFile _apt_DscFile;
+APT_HIDDEN debIFTypeDebianSourceDir _apt_DebianSourceDir;
 
 const pkgIndexFile::Type *debSourcesIndex::GetType() const
 {
@@ -893,3 +899,10 @@ const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const
    return &_apt_DebianSourceDir;
 }
                                                                        /*}}}*/
+
+debStatusIndex::~debStatusIndex() {}
+debPackagesIndex::~debPackagesIndex() {}
+debTranslationsIndex::~debTranslationsIndex() {}
+debSourcesIndex::~debSourcesIndex() {}
+
+debDebPkgFileIndex::~debDebPkgFileIndex() {}