From 699b209e5122f8fcd85fc4666c9b7020286ab0d0 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 13 Dec 2011 00:17:30 +0100 Subject: Allow the FileFd to use an external Compressor to uncompress a given file internally so that it is exported and can be used like a "normal" uncompressed file with FileFd This allows us to hide th zlib usage in the implementation and use gzip instead if we don't have zlib builtin (the same for other compressors). The code includes quiet a few FIXME's so while all tests are working it shouldn't be used just yet outside of libapt as it might break. --- ftparchive/multicompress.cc | 74 +++------------------------------------------ 1 file changed, 4 insertions(+), 70 deletions(-) (limited to 'ftparchive/multicompress.cc') diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc index bf0f858d9..37a713efd 100644 --- a/ftparchive/multicompress.cc +++ b/ftparchive/multicompress.cc @@ -16,6 +16,7 @@ // Include Files /*{{{*/ #include +#include #include #include #include @@ -261,73 +262,6 @@ bool MultiCompress::Finalize(unsigned long long &OutSize) return true; } /*}}}*/ -// MultiCompress::OpenCompress - Open the compressor /*{{{*/ -// --------------------------------------------------------------------- -/* This opens the compressor, either in compress mode or decompress - mode. FileFd is always the compressor input/output file, - OutFd is the created pipe, Input for Compress, Output for Decompress. */ -bool MultiCompress::OpenCompress(APT::Configuration::Compressor const &Prog, - pid_t &Pid,int const &FileFd,int &OutFd,bool const &Comp) -{ - Pid = -1; - - // No compression - if (Prog.Binary.empty() == true) - { - OutFd = dup(FileFd); - return true; - } - - // Create a data pipe - int Pipe[2] = {-1,-1}; - if (pipe(Pipe) != 0) - return _error->Errno("pipe",_("Failed to create subprocess IPC")); - for (int J = 0; J != 2; J++) - SetCloseExec(Pipe[J],true); - - if (Comp == true) - OutFd = Pipe[1]; - else - OutFd = Pipe[0]; - - // The child.. - Pid = ExecFork(); - if (Pid == 0) - { - if (Comp == true) - { - dup2(FileFd,STDOUT_FILENO); - dup2(Pipe[0],STDIN_FILENO); - } - else - { - dup2(FileFd,STDIN_FILENO); - dup2(Pipe[1],STDOUT_FILENO); - } - - SetCloseExec(STDOUT_FILENO,false); - SetCloseExec(STDIN_FILENO,false); - - std::vector Args; - Args.push_back(Prog.Binary.c_str()); - std::vector const * const addArgs = - (Comp == true) ? &(Prog.CompressArgs) : &(Prog.UncompressArgs); - for (std::vector::const_iterator a = addArgs->begin(); - a != addArgs->end(); ++a) - Args.push_back(a->c_str()); - Args.push_back(NULL); - - execvp(Args[0],(char **)&Args[0]); - cerr << _("Failed to exec compressor ") << Args[0] << endl; - _exit(100); - }; - if (Comp == true) - close(Pipe[0]); - else - close(Pipe[1]); - return true; -} - /*}}}*/ // MultiCompress::OpenOld - Open an old file /*{{{*/ // --------------------------------------------------------------------- /* This opens one of the original output files, possibly decompressing it. */ @@ -344,7 +278,7 @@ bool MultiCompress::OpenOld(int &Fd,pid_t &Proc) return false; // Decompress the file so we can read it - if (OpenCompress(Best->CompressProg,Proc,F.Fd(),Fd,false) == false) + if (ExecCompressor(Best->CompressProg,&Proc,F.Fd(),Fd,false) == false) return false; return true; @@ -374,8 +308,8 @@ bool MultiCompress::Child(int const &FD) // Start the compression children. for (Files *I = Outputs; I != 0; I = I->Next) { - if (OpenCompress(I->CompressProg,I->CompressProc,I->TmpFile.Fd(), - I->Fd,true) == false) + if (ExecCompressor(I->CompressProg,&(I->CompressProc),I->TmpFile.Fd(), + I->Fd,true) == false) return false; } -- cgit v1.2.3