diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-02-27 23:01:40 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-02-27 23:01:40 +0100 |
commit | 03bef78461c6f443187b60799402624326843396 (patch) | |
tree | 82befecf33cd7abd714a12502e7da0b20efd6133 /ftparchive | |
parent | 31273d9ff4fa1a6e073168e9cbaa91d1f53be853 (diff) |
- load the supported compressors from configuration
- support adding new compressors by configuration
Diffstat (limited to 'ftparchive')
-rw-r--r-- | ftparchive/multicompress.cc | 59 | ||||
-rw-r--r-- | ftparchive/multicompress.h | 21 | ||||
-rw-r--r-- | ftparchive/writer.cc | 1 |
3 files changed, 34 insertions, 47 deletions
diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc index c33414a11..f82879015 100644 --- a/ftparchive/multicompress.cc +++ b/ftparchive/multicompress.cc @@ -30,13 +30,6 @@ using namespace std; -const MultiCompress::CompType MultiCompress::Compressors[] = - {{".","",0,0,0,1}, - {"gzip",".gz","gzip","-9n","-d",2}, - {"bzip2",".bz2","bzip2","-9","-d",3}, - {"lzma",".lzma","lzma","-9","-d",4}, - {"xz",".xz","xz","-6","-d",5}, - {}}; // MultiCompress::MultiCompress - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -49,7 +42,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress, Outputter = -1; Input = 0; UpdateMTime = 0; - + /* Parse the compression string, a space separated lists of compresison types */ string::const_iterator I = Compress.begin(); @@ -62,13 +55,14 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress, for (; I != Compress.end() && !isspace(*I); I++); // Find the matching compressor - const CompType *Comp = Compressors; - for (; Comp->Name != 0; Comp++) - if (stringcmp(Start,I,Comp->Name) == 0) + std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors(); + std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin(); + for (; Comp != Compressors.end(); ++Comp) + if (stringcmp(Start,I,Comp->Name.c_str()) == 0) break; // Hmm.. unknown. - if (Comp->Name == 0) + if (Comp == Compressors.end()) { _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str()); continue; @@ -78,7 +72,7 @@ MultiCompress::MultiCompress(string const &Output,string const &Compress, Files *NewOut = new Files; NewOut->Next = Outputs; Outputs = NewOut; - NewOut->CompressProg = Comp; + NewOut->CompressProg = *Comp; NewOut->Output = Output+Comp->Extension; struct stat St; @@ -142,13 +136,14 @@ bool MultiCompress::GetStat(string const &Output,string const &Compress,struct s for (; I != Compress.end() && !isspace(*I); I++); // Find the matching compressor - const CompType *Comp = Compressors; - for (; Comp->Name != 0; Comp++) - if (stringcmp(Start,I,Comp->Name) == 0) + std::vector<APT::Configuration::Compressor> Compressors = APT::Configuration::getCompressors(); + std::vector<APT::Configuration::Compressor>::const_iterator Comp = Compressors.begin(); + for (; Comp != Compressors.end(); ++Comp) + if (stringcmp(Start,I,Comp->Name.c_str()) == 0) break; // Hmm.. unknown. - if (Comp->Name == 0) + if (Comp == Compressors.end()) continue; string Name = Output+Comp->Extension; @@ -269,13 +264,13 @@ bool MultiCompress::Finalize(unsigned long &OutSize) /* 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(const CompType *Prog,pid_t &Pid,int const &FileFd, - int &OutFd,bool const &Comp) +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 == 0) + if (Prog.Binary.empty() == true) { OutFd = dup(FileFd); return true; @@ -310,15 +305,17 @@ bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &File SetCloseExec(STDOUT_FILENO,false); SetCloseExec(STDIN_FILENO,false); - - const char *Args[3]; - Args[0] = Prog->Binary; - if (Comp == true) - Args[1] = Prog->CompArgs; - else - Args[1] = Prog->UnCompArgs; - Args[2] = 0; - execvp(Args[0],(char **)Args); + + std::vector<char const*> Args; + Args.push_back(Prog.Binary.c_str()); + std::vector<std::string> const * const addArgs = + (Comp == true) ? &(Prog.CompressArgs) : &(Prog.UncompressArgs); + for (std::vector<std::string>::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); }; @@ -336,7 +333,7 @@ bool MultiCompress::OpenOld(int &Fd,pid_t &Proc) { Files *Best = Outputs; for (Files *I = Outputs; I != 0; I = I->Next) - if (Best->CompressProg->Cost > I->CompressProg->Cost) + if (Best->CompressProg.Cost > I->CompressProg.Cost) Best = I; // Open the file @@ -415,7 +412,7 @@ bool MultiCompress::Child(int const &FD) for (Files *I = Outputs; I != 0; I = I->Next) { if (I->CompressProc != -1) - ExecWait(I->CompressProc,I->CompressProg->Binary,false); + ExecWait(I->CompressProc, I->CompressProg.Binary.c_str(), false); } if (_error->PendingError() == true) diff --git a/ftparchive/multicompress.h b/ftparchive/multicompress.h index 3ac3b8fb2..19dede174 100644 --- a/ftparchive/multicompress.h +++ b/ftparchive/multicompress.h @@ -20,28 +20,18 @@ #include <string> #include <apt-pkg/fileutl.h> +#include <apt-pkg/aptconfiguration.h> #include <stdio.h> #include <sys/types.h> class MultiCompress { - // Enumeration of all supported compressors - struct CompType - { - const char *Name; - const char *Extension; - const char *Binary; - const char *CompArgs; - const char *UnCompArgs; - unsigned char Cost; - }; - // An output file struct Files { string Output; - const CompType *CompressProg; - Files *Next; + APT::Configuration::Compressor CompressProg; + Files *Next; FileFd TmpFile; pid_t CompressProc; time_t OldMTime; @@ -51,10 +41,9 @@ class MultiCompress Files *Outputs; pid_t Outputter; mode_t Permissions; - static const CompType Compressors[]; - bool OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd, - int &OutFd,bool const &Comp); + bool OpenCompress(APT::Configuration::Compressor const &Prog, + pid_t &Pid,int const &FileFd, int &OutFd,bool const &Comp); bool Child(int const &Fd); bool Start(); bool Die(); diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 9462ebe27..9f12cbf3d 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -17,6 +17,7 @@ #include <apt-pkg/strutl.h> #include <apt-pkg/error.h> #include <apt-pkg/configuration.h> +#include <apt-pkg/aptconfiguration.h> #include <apt-pkg/md5.h> #include <apt-pkg/sha1.h> #include <apt-pkg/sha256.h> |