diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-14 22:35:03 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-14 22:35:03 +0100 |
commit | 12d1f5b3e295c589371bf7de27b7918310d08480 (patch) | |
tree | ea3c89ca71f1d5240e43b40c4f01e5921b7d22ab /ftparchive | |
parent | 52b47296f61ec3ca1075bbfb44982f5caa541e7c (diff) |
remove the second usage instance of ExecCompressor in ftparchive
by again using the FileFd directly
Diffstat (limited to 'ftparchive')
-rw-r--r-- | ftparchive/multicompress.cc | 42 | ||||
-rw-r--r-- | ftparchive/multicompress.h | 3 | ||||
-rw-r--r-- | ftparchive/writer.cc | 23 |
3 files changed, 18 insertions, 50 deletions
diff --git a/ftparchive/multicompress.cc b/ftparchive/multicompress.cc index 2a930ca6b..1fea589e2 100644 --- a/ftparchive/multicompress.cc +++ b/ftparchive/multicompress.cc @@ -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() && diff --git a/ftparchive/multicompress.h b/ftparchive/multicompress.h index 2dc7095d7..388fad22e 100644 --- a/ftparchive/multicompress.h +++ b/ftparchive/multicompress.h @@ -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, diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc index 27e53faf8..02777713c 100644 --- a/ftparchive/writer.cc +++ b/ftparchive/writer.cc @@ -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; } |