Browse Source

remove the second usage instance of ExecCompressor in ftparchive

by again using the FileFd directly
tags/debian/0.9.0
David Kalnischkies 9 years ago
parent
commit
12d1f5b3e2
3 changed files with 18 additions and 50 deletions
  1. +9
    -33
      ftparchive/multicompress.cc
  2. +1
    -2
      ftparchive/multicompress.h
  3. +8
    -15
      ftparchive/writer.cc

+ 9
- 33
ftparchive/multicompress.cc View File

@@ -260,7 +260,7 @@ bool MultiCompress::Finalize(unsigned long long &OutSize)
// MultiCompress::OpenOld - Open an old file /*{{{*/
// ---------------------------------------------------------------------
/* This opens one of the original output files, possibly decompressing it. */
bool MultiCompress::OpenOld(int &Fd,pid_t &Proc)
bool MultiCompress::OpenOld(FileFd &Fd)
{
Files *Best = Outputs;
for (Files *I = Outputs; I != 0; I = I->Next)
@@ -268,29 +268,9 @@ bool MultiCompress::OpenOld(int &Fd,pid_t &Proc)
Best = I;

// Open the file
FileFd F(Best->Output,FileFd::ReadOnly);
if (_error->PendingError() == true)
return false;
// Decompress the file so we can read it
if (ExecCompressor(Best->CompressProg,&Proc,F.Fd(),Fd,false) == false)
return false;
return true;
return Fd.Open(Best->Output, FileFd::ReadOnly, FileFd::Extension);
}
/*}}}*/
// MultiCompress::CloseOld - Close the old file /*{{{*/
// ---------------------------------------------------------------------
/* */
bool MultiCompress::CloseOld(int Fd,pid_t Proc)
{
close(Fd);
if (Proc != -1)
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
@@ -345,31 +325,27 @@ bool MultiCompress::Child(int const &FD)
// Check the MD5 of the lowest cost entity.
while (Missing == false)
{
int CompFd = -1;
pid_t Proc = -1;
if (OpenOld(CompFd,Proc) == false)
FileFd CompFd;
if (OpenOld(CompFd) == false)
{
_error->Discard();
break;
}
// Compute the hash
MD5Summation OldMD5;
unsigned long long NewFileSize = 0;
while (1)
{
int Res = read(CompFd,Buffer,sizeof(Buffer));
unsigned long long Res = 0;
if (CompFd.Read(Buffer,sizeof(Buffer), &Res) == false)
return _error->Errno("read",_("Failed to read while computing MD5"));
if (Res == 0)
break;
if (Res < 0)
return _error->Errno("read",_("Failed to read while computing MD5"));
NewFileSize += Res;
OldMD5.Add(Buffer,Res);
}
// Tidy the compressor
if (CloseOld(CompFd,Proc) == false)
return false;
CompFd.Close();

// Check the hash
if (OldMD5.Result() == MD5.Result() &&


+ 1
- 2
ftparchive/multicompress.h View File

@@ -51,8 +51,7 @@ class MultiCompress
unsigned long UpdateMTime;
bool Finalize(unsigned long long &OutSize);
bool OpenOld(int &Fd,pid_t &Proc);
bool CloseOld(int Fd,pid_t Proc);
bool OpenOld(FileFd &Fd);
static bool GetStat(std::string const &Output,std::string const &Compress,struct stat &St);
MultiCompress(std::string const &Output,std::string const &Compress,


+ 8
- 15
ftparchive/writer.cc View File

@@ -889,22 +889,16 @@ bool ContentsWriter::ReadFromPkgs(string const &PkgFile,string const &PkgCompres
MultiCompress Pkgs(PkgFile,PkgCompress,0,false);
if (_error->PendingError() == true)
return false;
// Open the package file
int CompFd = -1;
pid_t Proc = -1;
if (Pkgs.OpenOld(CompFd,Proc) == false)
FileFd Fd;
if (Pkgs.OpenOld(Fd) == false)
return false;
// No auto-close FD
FileFd Fd(CompFd,false);

pkgTagFile Tags(&Fd);
if (_error->PendingError() == true)
{
Pkgs.CloseOld(CompFd,Proc);
return false;
}

// Parse.
pkgTagSection Section;
while (Tags.Step(Section) == true)
@@ -926,11 +920,10 @@ bool ContentsWriter::ReadFromPkgs(string const &PkgFile,string const &PkgCompres
_error->DumpErrors();
}
}
// Tidy the compressor
if (Pkgs.CloseOld(CompFd,Proc) == false)
return false;
Fd.Close();

return true;
}



Loading…
Cancel
Save