summaryrefslogtreecommitdiff
path: root/apt-pkg/deb/debindexfile.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/deb/debindexfile.cc')
-rw-r--r--apt-pkg/deb/debindexfile.cc223
1 files changed, 197 insertions, 26 deletions
diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc
index 5b4289e92..49c6e8cc0 100644
--- a/apt-pkg/deb/debindexfile.cc
+++ b/apt-pkg/deb/debindexfile.cc
@@ -30,9 +30,11 @@
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/srcrecords.h>
+#include <apt-pkg/sptr.h>
#include <stdio.h>
#include <iostream>
+#include <sstream>
#include <string>
#include <sys/stat.h>
/*}}}*/
@@ -130,7 +132,7 @@ 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));
@@ -264,7 +266,7 @@ 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));
@@ -420,7 +422,7 @@ 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));
@@ -451,19 +453,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
@@ -634,7 +623,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)
@@ -683,14 +672,146 @@ APT_CONST bool debStatusIndex::Exists() const
}
/*}}}*/
+// debDebPkgFile - Single .deb file /*{{{*/
+debDebPkgFileIndex::debDebPkgFileIndex(std::string DebFile)
+ : pkgIndexFile(true), DebFile(DebFile)
+{
+ DebFileFullPath = flAbsPath(DebFile);
+}
+
+std::string debDebPkgFileIndex::ArchiveURI(std::string /*File*/) const
+{
+ return "file:" + DebFileFullPath;
+}
+
+bool debDebPkgFileIndex::Exists() const
+{
+ return FileExists(DebFile);
+}
+bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &debfile)
+{
+ // get the control data out of the deb file via dpkg-deb -I
+ std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg-deb");
+ std::vector<const char *> Args;
+ Args.push_back(dpkg.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((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
+ return _error->Error("Popen failed");
+
+ char buffer[1024];
+ do {
+ unsigned long long actual = 0;
+ if (PipeFd.Read(buffer, sizeof(buffer)-1, &actual) == false)
+ return _error->Errno("read", "Failed to read dpkg pipe");
+ if (actual == 0)
+ break;
+ buffer[actual] = '\0';
+ content << buffer;
+ } while(true);
+ ExecWait(Child, "Popen");
+
+ content << "Filename: " << debfile << "\n";
+ struct stat Buf;
+ if (stat(debfile.c_str(), &Buf) != 0)
+ return false;
+ content << "Size: " << Buf.st_size << "\n";
+
+ return true;
+}
+bool debDebPkgFileIndex::Merge(pkgCacheGenerator& Gen, OpProgress* Prog) const
+{
+ if(Prog)
+ Prog->SubProgress(0, "Reading deb file");
+
+ // write the control data to a tempfile
+ SPtr<FileFd> DebControl = GetTempFile("deb-file-" + flNotDir(DebFile));
+ if(DebControl == NULL)
+ return false;
+ std::ostringstream content;
+ if (GetContent(content, DebFile) == false)
+ return false;
+ std::string const contentstr = content.str();
+ DebControl->Write(contentstr.c_str(), contentstr.length());
+ // rewind for the listparser
+ DebControl->Seek(0);
+
+ // and give it to the list parser
+ debDebFileParser Parser(DebControl, DebFile);
+ if(Gen.SelectFile(DebFile, "local", *this) == false)
+ return _error->Error("Problem with SelectFile %s", DebFile.c_str());
+
+ pkgCache::PkgFileIterator File = Gen.GetCurFile();
+ File->Size = DebControl->Size();
+ File->mtime = DebControl->ModificationTime();
+
+ if (Gen.MergeList(Parser) == false)
+ return _error->Error("Problem with MergeLister for %s", DebFile.c_str());
+
+ return true;
+}
+pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const
+{
+ pkgCache::PkgFileIterator File = Cache.FileBegin();
+ for (; File.end() == false; ++File)
+ {
+ if (File.FileName() == NULL || DebFile != File.FileName())
+ continue;
+
+ return File;
+ }
+
+ return File;
+}
+unsigned long debDebPkgFileIndex::Size() const
+{
+ struct stat buf;
+ if(stat(DebFile.c_str(), &buf) != 0)
+ return 0;
+ return buf.st_size;
+}
+ /*}}}*/
+
+// debDscFileIndex stuff
+debDscFileIndex::debDscFileIndex(std::string &DscFile)
+ : pkgIndexFile(true), DscFile(DscFile)
+{
+}
+
+bool debDscFileIndex::Exists() const
+{
+ return FileExists(DscFile);
+}
+
+unsigned long debDscFileIndex::Size() const
+{
+ struct stat buf;
+ if(stat(DscFile.c_str(), &buf) == 0)
+ return buf.st_size;
+ return 0;
+}
+
+// DscFileIndex::CreateSrcParser - Get a parser for the .dsc file /*{{{*/
+pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
+{
+ if (!FileExists(DscFile))
+ return NULL;
+
+ 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:
@@ -700,12 +821,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:
@@ -715,10 +836,42 @@ class debIFTypeStatus : public pkgIndexFile::Type
};
debIFTypeStatus() {Label = "Debian dpkg status file";};
};
-static debIFTypeSrc _apt_Src;
-static debIFTypePkg _apt_Pkg;
-static debIFTypeTrans _apt_Trans;
-static debIFTypeStatus _apt_Status;
+class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type
+{
+ public:
+ virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
+ {
+ return new debDebFileRecordParser(File.FileName());
+ };
+ debIFTypeDebPkgFile() {Label = "deb Package file";};
+};
+class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type
+{
+ public:
+ virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string DscFile) const
+ {
+ return new debDscRecordParser(DscFile, NULL);
+ };
+ debIFTypeDscFile() {Label = "dsc File Source Index";};
+};
+class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type
+{
+ public:
+ virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string SourceDir) const
+ {
+ return new debDscRecordParser(SourceDir + string("/debian/control"), NULL);
+ };
+ debIFTypeDebianSourceDir() {Label = "debian/control File Source Index";};
+};
+
+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
+APT_HIDDEN debIFTypeDscFile _apt_DscFile;
+APT_HIDDEN debIFTypeDebianSourceDir _apt_DebianSourceDir;
const pkgIndexFile::Type *debSourcesIndex::GetType() const
{
@@ -736,5 +889,23 @@ const pkgIndexFile::Type *debStatusIndex::GetType() const
{
return &_apt_Status;
}
-
+const pkgIndexFile::Type *debDebPkgFileIndex::GetType() const
+{
+ return &_apt_DebPkgFile;
+}
+const pkgIndexFile::Type *debDscFileIndex::GetType() const
+{
+ return &_apt_DscFile;
+}
+const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const
+{
+ return &_apt_DebianSourceDir;
+}
/*}}}*/
+
+debStatusIndex::~debStatusIndex() {}
+debPackagesIndex::~debPackagesIndex() {}
+debTranslationsIndex::~debTranslationsIndex() {}
+debSourcesIndex::~debSourcesIndex() {}
+
+debDebPkgFileIndex::~debDebPkgFileIndex() {}