// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: debfile.cc,v 1.3 2003/02/10 00:36:12 doogie Exp $
+// $Id: debfile.cc,v 1.3.2.1 2004/01/16 18:58:50 mdz Exp $
/* ######################################################################
Debian Archive File (.deb)
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/debfile.h"
-#endif
+#include<config.h>
-#include <apti18n.h>
+#include <apt-pkg/database.h>
#include <apt-pkg/debfile.h>
#include <apt-pkg/extracttar.h>
#include <apt-pkg/error.h>
#include <apt-pkg/deblistparser.h>
+#include <apt-pkg/aptconfiguration.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <apti18n.h>
/*}}}*/
// DebFile::debDebFile - Constructor /*{{{*/
{
if (_error->PendingError() == true)
return;
-
- // Check the members for validity
- if (CheckMember("debian-binary") == false ||
- CheckMember("control.tar.gz") == false ||
- CheckMember("data.tar.gz") == false)
+
+ if (!CheckMember("debian-binary")) {
+ _error->Error(_("This is not a valid DEB archive, missing '%s' member"), "debian-binary");
+ return;
+ }
+
+ if (!CheckMember("control.tar.gz")) {
+ _error->Error(_("This is not a valid DEB archive, missing '%s' member"), "control.tar.gz");
+ return;
+ }
+
+ if (!CheckMember("data.tar.gz") &&
+ !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");
return;
+ }
}
/*}}}*/
// DebFile::CheckMember - Check if a named member is in the archive /*{{{*/
bool debDebFile::CheckMember(const char *Name)
{
if (AR.FindMember(Name) == 0)
- return _error->Error(_("This is not a valid DEB archive, missing '%s' member"),Name);
+ return false;
return true;
}
/*}}}*/
const ARArchive::Member *Member = AR.FindMember(Name);
if (Member == 0)
{
- _error->Error(_("Internal Error, could not locate member %s"),Name);
return 0;
}
if (File.Seek(Member->Start) == false)
// Prepare Tar
ControlExtract Extract;
- ExtractTar Tar(File,Member->Size);
+ ExtractTar Tar(File,Member->Size,"gzip");
if (_error->PendingError() == true)
return false;
// Get into the temporary directory
- string Cwd = SafeGetCWD();
- string Tmp;
+ std::string Cwd = SafeGetCWD();
+ std::string Tmp;
if (DB.GetMetaTmp(Tmp) == false)
return false;
if (chdir(Tmp.c_str()) != 0)
/* Simple wrapper around tar.. */
bool debDebFile::ExtractArchive(pkgDirStream &Stream)
{
- // Get the archive member and positition the file
- const ARArchive::Member *Member = AR.FindMember("data.tar.gz");
- if (Member == 0)
- return _error->Error(_("Internal Error, could not locate member"));
+ // 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());
+ if (Member == NULL)
+ continue;
+ Compressor = c->Binary;
+ break;
+ }
+
+ if (Member == NULL)
+ {
+ std::string ext = "data.tar.{";
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressor.begin();
+ c != compressor.end(); ++c)
+ ext.append(c->Extension.substr(1));
+ ext.append("}");
+ return _error->Error(_("Internal error, could not locate member %s"), ext.c_str());
+ }
+
if (File.Seek(Member->Start) == false)
return false;
-
+
// Prepare Tar
- ExtractTar Tar(File,Member->Size);
+ ExtractTar Tar(File,Member->Size,Compressor);
if (_error->PendingError() == true)
return false;
return Tar.Go(Stream);
pkgCache::VerIterator debDebFile::MergeControl(pkgDataBase &DB)
{
// Open the control file
- string Tmp;
+ std::string Tmp;
if (DB.GetMetaTmp(Tmp) == false)
return pkgCache::VerIterator(DB.GetCache());
FileFd Fd(Tmp + "control",FileFd::ReadOnly);
return false;
// Extract it.
- ExtractTar Tar(Deb.GetFile(),Member->Size);
+ ExtractTar Tar(Deb.GetFile(),Member->Size,"gzip");
if (Tar.Go(*this) == false)
return false;
Control[Length] = '\n';
Control[Length+1] = '\n';
if (Section.Scan(Control,Length+2) == false)
- return _error->Error(_("Unparsible control file"));
+ return _error->Error(_("Unparsable control file"));
return true;
}
/*}}}*/