summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-inst/contrib/extracttar.cc67
-rw-r--r--apt-pkg/contrib/fileutl.cc13
-rw-r--r--test/libapt/extracttar_test.cc41
-rw-r--r--test/libapt/makefile4
4 files changed, 61 insertions, 64 deletions
diff --git a/apt-inst/contrib/extracttar.cc b/apt-inst/contrib/extracttar.cc
index 2c86d0d01..c21a336f0 100644
--- a/apt-inst/contrib/extracttar.cc
+++ b/apt-inst/contrib/extracttar.cc
@@ -82,28 +82,9 @@ ExtractTar::~ExtractTar()
means we hit the end of the tar file but there was still gzip data. */
bool ExtractTar::Done(bool Force)
{
- InFd.Close();
- if (GZPid <= 0)
- return true;
-
- /* If there is a pending error then we are cleaning up gzip and are
- not interested in it's failures */
- if (_error->PendingError() == true)
- Force = true;
-
- // Make sure we clean it up!
- kill(GZPid,SIGINT);
- string confvar = string("dir::bin::") + DecompressProg;
- if (ExecWait(GZPid,_config->Find(confvar.c_str(),DecompressProg.c_str()).c_str(),
- Force) == false)
- {
- GZPid = -1;
- return Force;
- }
-
- GZPid = -1;
- return true;
+ return InFd.Close();
}
+
/*}}}*/
// ExtractTar::StartGzip - Startup gzip /*{{{*/
// ---------------------------------------------------------------------
@@ -118,43 +99,17 @@ bool ExtractTar::StartGzip()
return true;
}
- int Pipes[2];
- if (pipe(Pipes) != 0)
- return _error->Errno("pipe",_("Failed to create pipes"));
-
- // Fork off the process
- GZPid = ExecFork();
-
- // Spawn the subprocess
- if (GZPid == 0)
- {
- // Setup the FDs
- dup2(Pipes[1],STDOUT_FILENO);
- dup2(File.Fd(),STDIN_FILENO);
- int Fd = open("/dev/null",O_RDWR);
- if (Fd == -1)
- _exit(101);
- dup2(Fd,STDERR_FILENO);
- close(Fd);
- SetCloseExec(STDOUT_FILENO,false);
- SetCloseExec(STDIN_FILENO,false);
- SetCloseExec(STDERR_FILENO,false);
-
- const char *Args[3];
- string confvar = string("dir::bin::") + DecompressProg;
- string argv0 = _config->Find(confvar.c_str(),DecompressProg.c_str());
- Args[0] = argv0.c_str();
- Args[1] = "-d";
- Args[2] = 0;
- execvp(Args[0],(char **)Args);
- cerr << _("Failed to exec gzip ") << Args[0] << endl;
- _exit(100);
+ std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
+ std::vector<APT::Configuration::Compressor>::const_iterator compressor = compressors.begin();
+ for (; compressor != compressors.end(); compressor++) {
+ if (compressor->Name == DecompressProg) {
+ return InFd.OpenDescriptor(File.Fd(), FileFd::ReadOnly, *compressor, false);
+ }
}
- // Fix up our FDs
- InFd.OpenDescriptor(Pipes[0], FileFd::ReadOnly, FileFd::None, true);
- close(Pipes[1]);
- return true;
+ return _error->Error(_("Cannot find a configured compressor for '%s'"),
+ DecompressProg.c_str());
+
}
/*}}}*/
// ExtractTar::Go - Perform extraction /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 1be782bac..d7c9424cf 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -2006,12 +2006,13 @@ bool FileFd::Close()
{
if ((Flags & Compressed) != Compressed && iFd > 0 && close(iFd) != 0)
Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str());
- if (d != NULL)
- {
- Res &= d->CloseDown(FileName);
- delete d;
- d = NULL;
- }
+ }
+
+ if (d != NULL)
+ {
+ Res &= d->CloseDown(FileName);
+ delete d;
+ d = NULL;
}
if ((Flags & Replace) == Replace) {
diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc
new file mode 100644
index 000000000..b4e1fd37f
--- /dev/null
+++ b/test/libapt/extracttar_test.cc
@@ -0,0 +1,41 @@
+#include <apt-pkg/error.h>
+#include <apt-pkg/extracttar.h>
+#include <iostream>
+#include <stdlib.h>
+
+#include <gtest/gtest.h>
+#include "assert.h"
+
+class Stream : public pkgDirStream
+{
+ public:
+ int count;
+ Stream () { count = 0; }
+ virtual bool DoItem(Item &Itm,int &Fd) { (void)Itm; (void)Fd; count++; return true; }
+ virtual bool Fail(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; }
+ virtual bool FinishedFile(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; }
+ virtual bool Process(Item &Itm,const unsigned char * Data, unsigned long Size,unsigned long Pos) { (void)Itm; (void) Data; (void) Size; (void) Pos; return true; }
+ virtual ~Stream() {}
+};
+
+TEST(ExtractTar, ExtractTar)
+{
+ EXPECT_EQ(system("tar c makefile | gzip > tar.tgz"), 0);
+
+ FileFd fd("tar.tgz", FileFd::ReadOnly);
+ unlink("tar.tgz");
+ ExtractTar tar(fd, -1, "gzip");
+
+ // Run multiple times, because we want to check not only that extraction
+ // works, but also that it works multiple times (important for python-apt)
+ for (int i = 0; i < 5; i++) {
+ Stream stream;
+ fd.Seek(0);
+ tar.Go(stream);
+ if (_error->PendingError()) {
+ _error->DumpErrors();
+ EXPECT_FALSE(true);
+ }
+ EXPECT_EQ(stream.count, 1);
+ }
+}
diff --git a/test/libapt/makefile b/test/libapt/makefile
index c078cc568..5ff9cf68a 100644
--- a/test/libapt/makefile
+++ b/test/libapt/makefile
@@ -15,8 +15,8 @@ test: $(BIN)/gtest$(BASENAME)
$(BIN)/gtest$(BASENAME): $(LIB)/gtest.a
PROGRAM = gtest${BASENAME}
-SLIBS = -lapt-pkg -lapt-private -pthread $(LIB)/gtest.a
-LIB_MAKES = apt-pkg/makefile apt-private/makefile
+SLIBS = -lapt-pkg -lapt-private -lapt-inst -pthread $(LIB)/gtest.a
+LIB_MAKES = apt-pkg/makefile apt-private/makefile apt-inst/makefile
SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc)
include $(PROGRAM_H)