// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: multicompress.cc,v 1.2 2001/02/20 07:03:18 jgg Exp $
+// $Id: multicompress.cc,v 1.4 2003/02/10 07:34:41 doogie Exp $
/* ######################################################################
MultiCompressor
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "multicompress.h"
-#endif
-
#include "multicompress.h"
+#include <apti18n.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/error.h>
#include <apt-pkg/md5.h>
#include <sys/stat.h>
#include <utime.h>
#include <unistd.h>
+#include <iostream>
/*}}}*/
+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},
{}};
// 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 */
// Hmm.. unknown.
if (Comp->Name == 0)
{
- _error->Warning("Unknown Compresison Algorithm '%s'",string(Start,I).c_str());
+ _error->Warning(_("Unknown compression algorithm '%s'"),string(Start,I).c_str());
continue;
}
if (Outputs == 0)
{
- _error->Error("Compressed output %s needs a compression set",Output.c_str());
+ _error->Error(_("Compressed output %s needs a compression set"),Output.c_str());
return;
}
/* 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 */
// Create a data pipe
int Pipe[2] = {-1,-1};
if (pipe(Pipe) != 0)
- return _error->Errno("pipe","Failed to create IPC pipe to subprocess");
+ return _error->Errno("pipe",_("Failed to create IPC pipe to subprocess"));
for (int I = 0; I != 2; I++)
SetCloseExec(Pipe[I],true);
close(Pipe[0]);
Input = fdopen(Pipe[1],"w");
if (Input == 0)
- return _error->Errno("fdopen","Failed to create FILE*");
+ return _error->Errno("fdopen",_("Failed to create FILE*"));
if (Outputter == -1)
- return _error->Errno("fork","Failed to fork");
+ return _error->Errno("fork",_("Failed to fork"));
return true;
}
/*}}}*/
fclose(Input);
Input = 0;
- bool Res = ExecWait(Outputter,"Compress Child",false);
+ bool Res = ExecWait(Outputter,_("Compress child"),false);
Outputter = -1;
return Res;
}
{
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)
/* 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,int &Pid,int FileFd,
- int &OutFd,bool Comp)
+bool MultiCompress::OpenCompress(const CompType *Prog,pid_t &Pid,int const &FileFd,
+ int &OutFd,bool const &Comp)
{
Pid = -1;
// Create a data pipe
int Pipe[2] = {-1,-1};
if (pipe(Pipe) != 0)
- return _error->Errno("pipe","Failed to create subprocess IPC");
+ return _error->Errno("pipe",_("Failed to create subprocess IPC"));
for (int J = 0; J != 2; J++)
SetCloseExec(Pipe[J],true);
Args[1] = Prog->UnCompArgs;
Args[2] = 0;
execvp(Args[0],(char **)Args);
- cerr << "Failed to exec compressor " << Args[0] << endl;
+ cerr << _("Failed to exec compressor ") << Args[0] << endl;
_exit(100);
};
if (Comp == true)
// MultiCompress::OpenOld - Open an old file /*{{{*/
// ---------------------------------------------------------------------
/* This opens one of the original output files, possibly decompressing it. */
-bool MultiCompress::OpenOld(int &Fd,int &Proc)
+bool MultiCompress::OpenOld(int &Fd,pid_t &Proc)
{
Files *Best = Outputs;
for (Files *I = Outputs; I != 0; I = I->Next)
// MultiCompress::CloseOld - Close the old file /*{{{*/
// ---------------------------------------------------------------------
/* */
-bool MultiCompress::CloseOld(int Fd,int Proc)
+bool MultiCompress::CloseOld(int Fd,pid_t Proc)
{
close(Fd);
if (Proc != -1)
- if (ExecWait(Proc,"decompressor",false) == false)
+ if (ExecWait(Proc,_("decompressor"),false) == false)
return false;
return true;
}
// 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)
{
if (write(I->Fd,Buffer,Res) != Res)
{
- _error->Errno("write","IO to subprocess/file failed");
+ _error->Errno("write",_("IO to subprocess/file failed"));
break;
}
}
while (Missing == false)
{
int CompFd = -1;
- int Proc = -1;
+ pid_t Proc = -1;
if (OpenOld(CompFd,Proc) == false)
{
_error->Discard();
if (Res == 0)
break;
if (Res < 0)
- return _error->Errno("read","Failed to read while computing MD5");
+ return _error->Errno("read",_("Failed to read while computing MD5"));
NewFileSize += Res;
OldMD5.Add(Buffer,Res);
}
{
I->TmpFile.Close();
if (unlink(I->TmpFile.Name().c_str()) != 0)
- _error->Errno("unlink","Problem unlinking %s",
+ _error->Errno("unlink",_("Problem unlinking %s"),
I->TmpFile.Name().c_str());
}
return !_error->PendingError();
fchmod(I->TmpFile.Fd(),Permissions);
if (rename(I->TmpFile.Name().c_str(),I->Output.c_str()) != 0)
- _error->Errno("rename","Failed to rename %s to %s",
+ _error->Errno("rename",_("Failed to rename %s to %s"),
I->TmpFile.Name().c_str(),I->Output.c_str());
I->TmpFile.Close();
}