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. --- apt-pkg/indexcopy.cc | 97 ++++------------------------------------------------ 1 file changed, 6 insertions(+), 91 deletions(-) (limited to 'apt-pkg/indexcopy.cc') diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index f6457aa39..3747e3570 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -38,65 +38,6 @@ using namespace std; -// DecompressFile - wrapper for decompressing compressed files /*{{{*/ -// --------------------------------------------------------------------- -/* */ -bool DecompressFile(string Filename, int *fd, off_t *FileSize) -{ - struct stat Buf; - *fd = -1; - - std::vector const compressor = APT::Configuration::getCompressors(); - std::vector::const_iterator UnCompress; - std::string file = std::string(Filename).append(UnCompress->Extension); - for (UnCompress = compressor.begin(); UnCompress != compressor.end(); ++UnCompress) - { - if (stat(file.c_str(), &Buf) == 0) - break; - } - - if (UnCompress == compressor.end()) - return _error->Errno("decompressor", "Unable to parse file"); - - *FileSize = Buf.st_size; - - // 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); - - *fd = Pipe[1]; - - // The child.. - pid_t Pid = ExecFork(); - if (Pid == 0) - { - dup2(Pipe[1],STDOUT_FILENO); - SetCloseExec(STDOUT_FILENO, false); - - std::vector Args; - Args.push_back(UnCompress->Binary.c_str()); - for (std::vector::const_iterator a = UnCompress->UncompressArgs.begin(); - a != UnCompress->UncompressArgs.end(); ++a) - Args.push_back(a->c_str()); - Args.push_back("--stdout"); - Args.push_back(file.c_str()); - Args.push_back(NULL); - - execvp(Args[0],(char **)&Args[0]); - cerr << _("Failed to exec compressor ") << Args[0] << endl; - _exit(100); - } - - // Wait for decompress to finish - if (ExecWait(Pid, UnCompress->Binary.c_str(), false) == false) - return false; - - return true; -} - /*}}}*/ // IndexCopy::CopyPackages - Copy the package files from the CD /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -142,24 +83,10 @@ bool IndexCopy::CopyPackages(string CDROM,string Name,vector &List, for (vector::iterator I = List.begin(); I != List.end(); ++I) { string OrigPath = string(*I,CDROM.length()); - off_t FileSize = 0; // Open the package file - FileFd Pkg; - if (RealFileExists(*I + GetFileName()) == true) - { - Pkg.Open(*I + GetFileName(),FileFd::ReadOnly); - FileSize = Pkg.Size(); - } - else - { - int fd; - if (!DecompressFile(string(*I + GetFileName()), &fd, &FileSize)) - return _error->Errno("decompress","Decompress failed for %s", - string(*I + GetFileName()).c_str()); - Pkg.Fd(dup(fd)); - Pkg.Seek(0); - } + FileFd Pkg(*I + GetFileName(), FileFd::ReadOnly, FileFd::Extension); + off_t const FileSize = Pkg.Size(); pkgTagFile Parser(&Pkg); if (_error->PendingError() == true) @@ -868,23 +795,11 @@ bool TranslationsCopy::CopyTranslations(string CDROM,string Name, /*{{{*/ for (vector::iterator I = List.begin(); I != List.end(); ++I) { string OrigPath = string(*I,CDROM.length()); - off_t FileSize = 0; - + // Open the package file - FileFd Pkg; - if (RealFileExists(*I) == true) - { - Pkg.Open(*I,FileFd::ReadOnly); - FileSize = Pkg.Size(); - } - else - { - int fd; - if (!DecompressFile(*I, &fd, &FileSize)) - return _error->Errno("decompress","Decompress failed for %s", (*I).c_str()); - Pkg.Fd(dup(fd)); - Pkg.Seek(0); - } + FileFd Pkg(*I, FileFd::ReadOnly, FileFd::Extension); + off_t const FileSize = Pkg.Size(); + pkgTagFile Parser(&Pkg); if (_error->PendingError() == true) return false; -- cgit v1.2.3