X-Git-Url: https://git.hcoop.net/ntk/apt.git/blobdiff_plain/3826564e07eaffb05eca5af34a0e76f6f161b89c..ea54214002c09eeb4dd498d97a564471ec9993c5:/ftparchive/multicompress.cc diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc index 5073e98a..04560f4a 100644 --- a/ftparchive/multicompress.cc +++ b/ftparchive/multicompress.cc @@ -14,44 +14,37 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "multicompress.h" -#endif +#include -#include "multicompress.h" - -#include #include #include #include - + #include #include #include #include -#include +#include + +#include "multicompress.h" +#include /*}}}*/ using namespace std; -const MultiCompress::CompType MultiCompress::Compressors[] = - {{".","",0,0,0,1}, - {"gzip",".gz","gzip","-9n","-d",2}, - {"bzip2",".bz2","bzip2","-9","-d",3}, - {}}; // MultiCompress::MultiCompress - Constructor /*{{{*/ // --------------------------------------------------------------------- /* Setup the file outputs, compression modes and fork the writer child */ -MultiCompress::MultiCompress(string Output,string Compress, - mode_t Permissions,bool Write) +MultiCompress::MultiCompress(string const &Output,string const &Compress, + mode_t const &Permissions,bool const &Write) : + Permissions(Permissions) { Outputs = 0; Outputter = -1; Input = 0; UpdateMTime = 0; - this->Permissions = Permissions; - + /* Parse the compression string, a space separated lists of compresison types */ string::const_iterator I = Compress.begin(); @@ -64,15 +57,16 @@ MultiCompress::MultiCompress(string Output,string 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 Compressors = APT::Configuration::getCompressors(); + std::vector::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 Compresison Algorithm '%s'"),string(Start,I).c_str()); + _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str()); continue; } @@ -80,7 +74,7 @@ MultiCompress::MultiCompress(string Output,string Compress, Files *NewOut = new Files; NewOut->Next = Outputs; Outputs = NewOut; - NewOut->CompressProg = Comp; + NewOut->CompressProg = *Comp; NewOut->Output = Output+Comp->Extension; struct stat St; @@ -129,7 +123,7 @@ MultiCompress::~MultiCompress() /* This checks each compressed file to make sure it exists and returns stat information for a random file from the collection. False means one or more of the files is missing. */ -bool MultiCompress::GetStat(string Output,string Compress,struct stat &St) +bool MultiCompress::GetStat(string const &Output,string const &Compress,struct stat &St) { /* Parse the compression string, a space separated lists of compresison types */ @@ -144,13 +138,14 @@ bool MultiCompress::GetStat(string Output,string Compress,struct stat &St) 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 Compressors = APT::Configuration::getCompressors(); + std::vector::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; @@ -212,7 +207,7 @@ bool MultiCompress::Die() fclose(Input); Input = 0; - bool Res = ExecWait(Outputter,_("Compress Child"),false); + bool Res = ExecWait(Outputter,_("Compress child"),false); Outputter = -1; return Res; } @@ -235,7 +230,7 @@ bool MultiCompress::Finalize(unsigned long &OutSize) { struct stat St; if (stat(I->Output.c_str(),&St) != 0) - return _error->Error(_("Internal Error, Failed to create %s"), + return _error->Error(_("Internal error, failed to create %s"), I->Output.c_str()); if (I->OldMTime != St.st_mtime) @@ -271,13 +266,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 FileFd, - int &OutFd,bool 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; @@ -312,15 +307,17 @@ bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int FileFd, 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 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); }; @@ -338,7 +335,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 @@ -368,11 +365,11 @@ bool MultiCompress::CloseOld(int Fd,pid_t Proc) // MultiCompress::Child - The writer child /*{{{*/ // --------------------------------------------------------------------- /* The child process forks a bunch of compression children and takes - input on FD and passes it to all the compressor childer. On the way it + input on FD and passes it to all the compressor child. On the way it computes the MD5 of the raw data. After this the raw data in the original files is compared to see if this data is new. If the data is new then the temp files are renamed, otherwise they are erased. */ -bool MultiCompress::Child(int FD) +bool MultiCompress::Child(int const &FD) { // Start the compression children. for (Files *I = Outputs; I != 0; I = I->Next) @@ -417,7 +414,7 @@ bool MultiCompress::Child(int 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)