]> git.saurik.com Git - apt.git/blobdiff - apt-inst/deb/debfile.cc
DebFile: Refactor ExtractTarMember() out from ExtractArchive()
[apt.git] / apt-inst / deb / debfile.cc
index e80d8c73581a664c54e9a1414b69f0b6a69f2317..15db1a7fcb6ca54b7c924b2d338811aada8805be 100644 (file)
@@ -51,8 +51,7 @@ debDebFile::debDebFile(FileFd &File) : File(File), AR(File)
        !CheckMember("data.tar.bz2") &&
        !CheckMember("data.tar.lzma") &&
        !CheckMember("data.tar.xz")) {
-      // FIXME: add data.tar.xz here - adding it now would require a Translation round for a very small gain
-      _error->Error(_("This is not a valid DEB archive, it has no '%s', '%s' or '%s' member"), "data.tar.gz", "data.tar.bz2", "data.tar.lzma");
+      _error->Error(_("This is not a valid DEB archive, missing '%s' member"), "data.tar");
       return;
    }
 }
@@ -89,57 +88,20 @@ const ARArchive::Member *debDebFile::GotoMember(const char *Name)
    return Member;
 }
                                                                        /*}}}*/
-// DebFile::ExtractControl - Extract Control information               /*{{{*/
-// ---------------------------------------------------------------------
-/* Extract the control information into the Database's temporary 
-   directory. */
-bool debDebFile::ExtractControl(pkgDataBase &DB)
-{
-   // Get the archive member and positition the file
-   const ARArchive::Member *Member = GotoMember("control.tar.gz");
-   if (Member == 0)
-      return false;
-      
-   // Prepare Tar
-   ControlExtract Extract;
-   ExtractTar Tar(File,Member->Size,"gzip");
-   if (_error->PendingError() == true)
-      return false;
-   
-   // Get into the temporary directory
-   string Cwd = SafeGetCWD();
-   string Tmp;
-   if (DB.GetMetaTmp(Tmp) == false)
-      return false;
-   if (chdir(Tmp.c_str()) != 0)
-      return _error->Errno("chdir",_("Couldn't change to %s"),Tmp.c_str());
-   
-   // Do extraction
-   if (Tar.Go(Extract) == false)
-      return false;
-   
-   // Switch out of the tmp directory.
-   if (chdir(Cwd.c_str()) != 0)
-      chdir("/");
-   
-   return true;
-}
-                                                                       /*}}}*/
-// DebFile::ExtractArchive - Extract the archive data itself           /*{{{*/
+// DebFile::ExtractTarMember - Extract the contents of a tar member    /*{{{*/
 // ---------------------------------------------------------------------
 /* Simple wrapper around tar.. */
-bool debDebFile::ExtractArchive(pkgDirStream &Stream)
+bool debDebFile::ExtractTarMember(pkgDirStream &Stream,const char *Name)
 {
    // Get the archive member
    const ARArchive::Member *Member = NULL;
    std::string Compressor;
 
-   std::string const data = "data.tar";
    std::vector<APT::Configuration::Compressor> compressor = APT::Configuration::getCompressors();
    for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
        c != compressor.end(); ++c)
    {
-      Member = AR.FindMember(std::string(data).append(c->Extension).c_str());
+      Member = AR.FindMember(std::string(Name).append(c->Extension).c_str());
       if (Member == NULL)
         continue;
       Compressor = c->Binary;
@@ -148,7 +110,7 @@ bool debDebFile::ExtractArchive(pkgDirStream &Stream)
 
    if (Member == NULL)
    {
-      std::string ext = "data.tar.{";
+      std::string ext = std::string(Name) + ".{";
       for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
           c != compressor.end(); ++c)
         ext.append(c->Extension.substr(1));
@@ -166,30 +128,12 @@ bool debDebFile::ExtractArchive(pkgDirStream &Stream)
    return Tar.Go(Stream);
 }
                                                                        /*}}}*/
-// DebFile::MergeControl - Merge the control information               /*{{{*/
+// DebFile::ExtractArchive - Extract the archive data itself           /*{{{*/
 // ---------------------------------------------------------------------
-/* This reads the extracted control file into the cache and returns the
-   version that was parsed. All this really does is select the correct
-   parser and correct file to parse. */
-pkgCache::VerIterator debDebFile::MergeControl(pkgDataBase &DB)
+/* Simple wrapper around DebFile::ExtractTarMember. */
+bool debDebFile::ExtractArchive(pkgDirStream &Stream)
 {
-   // Open the control file
-   string Tmp;
-   if (DB.GetMetaTmp(Tmp) == false)
-      return pkgCache::VerIterator(DB.GetCache());
-   FileFd Fd(Tmp + "control",FileFd::ReadOnly);
-   if (_error->PendingError() == true)
-      return pkgCache::VerIterator(DB.GetCache());
-   
-   // Parse it
-   debListParser Parse(&Fd);
-   pkgCache::VerIterator Ver(DB.GetCache());
-   if (DB.GetGenerator().MergeList(Parse,&Ver) == false)
-      return pkgCache::VerIterator(DB.GetCache());
-   
-   if (Ver.end() == true)
-      _error->Error(_("Failed to locate a valid control file"));
-   return Ver;
+   return ExtractTarMember(Stream, "data.tar");
 }
                                                                        /*}}}*/