diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-13 00:17:30 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-13 00:17:30 +0100 |
commit | 699b209e5122f8fcd85fc4666c9b7020286ab0d0 (patch) | |
tree | 0fca0e56e0f6bb03d4f1f8517f4c217e984875d6 /apt-pkg/indexcopy.cc | |
parent | 032bd56ff86166fd4b6a8f69bd9d5d1bc57b886e (diff) |
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.
Diffstat (limited to 'apt-pkg/indexcopy.cc')
-rw-r--r-- | apt-pkg/indexcopy.cc | 97 |
1 files changed, 6 insertions, 91 deletions
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<APT::Configuration::Compressor> const compressor = APT::Configuration::getCompressors(); - std::vector<APT::Configuration::Compressor>::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<char const*> Args; - Args.push_back(UnCompress->Binary.c_str()); - for (std::vector<std::string>::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<string> &List, for (vector<string>::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<string>::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; |