diff options
Diffstat (limited to 'methods')
-rw-r--r-- | methods/ftp.cc | 18 | ||||
-rw-r--r-- | methods/ftp.h | 6 | ||||
-rw-r--r-- | methods/gzip.cc | 73 | ||||
-rw-r--r-- | methods/http.cc | 26 | ||||
-rw-r--r-- | methods/http.h | 6 | ||||
-rw-r--r-- | methods/rsh.cc | 14 | ||||
-rw-r--r-- | methods/rsh.h | 8 |
7 files changed, 94 insertions, 57 deletions
diff --git a/methods/ftp.cc b/methods/ftp.cc index 524f799c3..edd150699 100644 --- a/methods/ftp.cc +++ b/methods/ftp.cc @@ -1,9 +1,9 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: ftp.cc,v 1.23 2001/02/23 07:19:49 jgg Exp $ +// $Id: ftp.cc,v 1.24 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### - HTTP Aquire Method - This is the FTP aquire method for APT. + FTP Aquire Method - This is the FTP aquire method for APT. This is a very simple implementation that does not try to optimize at all. Commands are sent syncronously with the FTP server (as the @@ -18,7 +18,7 @@ #include <apt-pkg/fileutl.h> #include <apt-pkg/acquire-method.h> #include <apt-pkg/error.h> -#include <apt-pkg/md5.h> +#include <apt-pkg/hashes.h> #include <sys/stat.h> #include <sys/time.h> @@ -825,7 +825,7 @@ bool FTPConn::Finalize() /* This opens a data connection, sends REST and RETR and then transfers the file over. */ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long Resume, - MD5Summation &MD5,bool &Missing) + Hashes &Hash,bool &Missing) { Missing = false; if (CreateDataFd() == false) @@ -849,7 +849,7 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long Resume, if (Resume != 0) { - if (MD5.AddFD(To.Fd(),Resume) == false) + if (Hash.AddFD(To.Fd(),Resume) == false) { _error->Errno("read","Problem hashing file"); return false; @@ -893,7 +893,7 @@ bool FTPConn::Get(const char *Path,FileFd &To,unsigned long Resume, break; } - MD5.Add(Buffer,Res); + Hash.Add(Buffer,Res); if (To.Write(Buffer,Res) == false) { Close(); @@ -1022,7 +1022,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) } // Open the file - MD5Summation MD5; + Hashes Hash; { FileFd Fd(Itm->DestFile,FileFd::WriteAny); if (_error->PendingError() == true) @@ -1035,7 +1035,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) FailFd = Fd.Fd(); bool Missing; - if (Server->Get(File,Fd,Res.ResumePoint,MD5,Missing) == false) + if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing) == false) { Fd.Close(); @@ -1056,7 +1056,7 @@ bool FtpMethod::Fetch(FetchItem *Itm) } Res.LastModified = FailTime; - Res.MD5Sum = MD5.Result(); + Res.MD5Sum = Hash.MD5.Result(); // Timestamp struct utimbuf UBuf; diff --git a/methods/ftp.h b/methods/ftp.h index f791195b3..1bcea41b6 100644 --- a/methods/ftp.h +++ b/methods/ftp.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- -// Description /*{{{*/// $Id: ftp.h,v 1.3 2001/02/20 07:03:18 jgg Exp $ -// $Id: ftp.h,v 1.3 2001/02/20 07:03:18 jgg Exp $ +// Description /*{{{*/// $Id: ftp.h,v 1.4 2001/03/06 07:15:29 jgg Exp $ +// $Id: ftp.h,v 1.4 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### FTP Aquire Method - This is the FTP aquire method for APT. @@ -56,7 +56,7 @@ class FTPConn bool Size(const char *Path,unsigned long &Size); bool ModTime(const char *Path, time_t &Time); bool Get(const char *Path,FileFd &To,unsigned long Resume, - MD5Summation &MD5,bool &Missing); + Hashes &MD5,bool &Missing); FTPConn(URI Srv); ~FTPConn(); diff --git a/methods/gzip.cc b/methods/gzip.cc index f58a7263d..4a52c7a0c 100644 --- a/methods/gzip.cc +++ b/methods/gzip.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: gzip.cc,v 1.11 2001/03/06 03:11:22 jgg Exp $ +// $Id: gzip.cc,v 1.12 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### GZip method - Take a file URI in and decompress it into the target @@ -13,11 +13,13 @@ #include <apt-pkg/error.h> #include <apt-pkg/acquire-method.h> #include <apt-pkg/strutl.h> +#include <apt-pkg/hashes.h> #include <sys/stat.h> #include <unistd.h> #include <utime.h> #include <stdio.h> +#include <errno.h> /*}}}*/ class GzipMethod : public pkgAcqMethod @@ -29,6 +31,7 @@ class GzipMethod : public pkgAcqMethod GzipMethod() : pkgAcqMethod("1.1",SingleInstance | SendConfig) {}; }; + // GzipMethod::Fetch - Decompress the passed URI /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -36,45 +39,74 @@ bool GzipMethod::Fetch(FetchItem *Itm) { URI Get = Itm->Uri; string Path = Get.Host + Get.Path; // To account for relative paths - string GzipPath = _config->Find("Dir::bin::gzip","gzip"); FetchResult Res; Res.Filename = Itm->DestFile; URIStart(Res); - // Open the source and destintation files + // Open the source and destination files FileFd From(Path,FileFd::ReadOnly); - FileFd To(Itm->DestFile,FileFd::WriteEmpty); - To.EraseOnFailure(); - if (_error->PendingError() == true) - return false; - + + int GzOut[2]; + if (pipe(GzOut) < 0) + return _error->Errno("pipe","Couldn't open pipe for gzip"); + // Fork gzip - int Process = fork(); - if (Process < 0) - return _error->Errno("fork",string("Couldn't fork "+GzipPath).c_str()); - - // The child + int Process = ExecFork(); if (Process == 0) { + close(GzOut[0]); dup2(From.Fd(),STDIN_FILENO); - dup2(To.Fd(),STDOUT_FILENO); + dup2(GzOut[1],STDOUT_FILENO); From.Close(); - To.Close(); + close(GzOut[1]); SetCloseExec(STDIN_FILENO,false); SetCloseExec(STDOUT_FILENO,false); const char *Args[3]; - Args[0] = GzipPath.c_str(); + Args[0] = _config->Find("Dir::bin::gzip","gzip").c_str(); Args[1] = "-d"; Args[2] = 0; execvp(Args[0],(char **)Args); - exit(100); + _exit(100); } From.Close(); + close(GzOut[1]); + + FileFd FromGz(GzOut[0]); // For autoclose + FileFd To(Itm->DestFile,FileFd::WriteEmpty); + To.EraseOnFailure(); + if (_error->PendingError() == true) + return false; + + // Read data from gzip, generate checksums and write + Hashes Hash; + bool Failed = false; + while (1) + { + unsigned char Buffer[4*1024]; + unsigned long Count; + + Count = read(GzOut[0],Buffer,sizeof(Buffer)); + if (Count < 0 && errno == EINTR) + continue; + + if (Count < 0) + { + _error->Errno("read", "Read error from gzip process"); + Failed = true; + break; + } + + if (Count == 0) + break; + + Hash.Add(Buffer,Count); + To.Write(Buffer,Count); + } // Wait for gzip to finish - if (ExecWait(Process,GzipPath.c_str(),false) == false) + if (ExecWait(Process,_config->Find("Dir::bin::gzip","gzip").c_str(),false) == false) { To.OpFail(); return false; @@ -82,6 +114,9 @@ bool GzipMethod::Fetch(FetchItem *Itm) To.Close(); + if (Failed == true) + return false; + // Transfer the modification times struct stat Buf; if (stat(Path.c_str(),&Buf) != 0) @@ -99,6 +134,8 @@ bool GzipMethod::Fetch(FetchItem *Itm) // Return a Done response Res.LastModified = Buf.st_mtime; Res.Size = Buf.st_size; + Res.MD5Sum = Hash.MD5.Result(); + URIDone(Res); return true; diff --git a/methods/http.cc b/methods/http.cc index c1c5d8a4a..0c520b33c 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: http.cc,v 1.49 2001/02/23 07:19:49 jgg Exp $ +// $Id: http.cc,v 1.50 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### HTTP Aquire Method - This is the HTTP aquire method for APT. @@ -28,7 +28,7 @@ #include <apt-pkg/fileutl.h> #include <apt-pkg/acquire-method.h> #include <apt-pkg/error.h> -#include <apt-pkg/md5.h> +#include <apt-pkg/hashes.h> #include <sys/stat.h> #include <sys/time.h> @@ -57,7 +57,7 @@ bool Debug = false; // CircleBuf::CircleBuf - Circular input buffer /*{{{*/ // --------------------------------------------------------------------- /* */ -CircleBuf::CircleBuf(unsigned long Size) : Size(Size), MD5(0) +CircleBuf::CircleBuf(unsigned long Size) : Size(Size), Hash(0) { Buf = new unsigned char[Size]; Reset(); @@ -73,10 +73,10 @@ void CircleBuf::Reset() StrPos = 0; MaxGet = (unsigned int)-1; OutQueue = string(); - if (MD5 != 0) + if (Hash != 0) { - delete MD5; - MD5 = new MD5Summation; + delete Hash; + Hash = new Hashes; } }; /*}}}*/ @@ -182,8 +182,8 @@ bool CircleBuf::Write(int Fd) return false; } - if (MD5 != 0) - MD5->Add(Buf + (OutP%Size),Res); + if (Hash != 0) + Hash->Add(Buf + (OutP%Size),Res); OutP += Res; } @@ -892,14 +892,14 @@ int HttpMethod::DealWithHeaders(FetchResult &Res,ServerState *Srv) // Set the start point lseek(File->Fd(),0,SEEK_END); - delete Srv->In.MD5; - Srv->In.MD5 = new MD5Summation; + delete Srv->In.Hash; + Srv->In.Hash = new Hashes; - // Fill the MD5 Hash if the file is non-empty (resume) + // Fill the Hash if the file is non-empty (resume) if (Srv->StartPos > 0) { lseek(File->Fd(),0,SEEK_SET); - if (Srv->In.MD5->AddFD(File->Fd(),Srv->StartPos) == false) + if (Srv->In.Hash->AddFD(File->Fd(),Srv->StartPos) == false) { _error->Errno("read","Problem hashing file"); return 5; @@ -1109,7 +1109,7 @@ int HttpMethod::Loop() // Send status to APT if (Result == true) { - Res.MD5Sum = Server->In.MD5->Result(); + Res.MD5Sum = Server->In.Hash->MD5.Result(); URIDone(Res); } else diff --git a/methods/http.h b/methods/http.h index 2569c2921..07a65d702 100644 --- a/methods/http.h +++ b/methods/http.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- -// Description /*{{{*/// $Id: http.h,v 1.9 2001/02/20 07:03:18 jgg Exp $ -// $Id: http.h,v 1.9 2001/02/20 07:03:18 jgg Exp $ +// Description /*{{{*/// $Id: http.h,v 1.10 2001/03/06 07:15:29 jgg Exp $ +// $Id: http.h,v 1.10 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### HTTP Aquire Method - This is the HTTP aquire method for APT. @@ -46,7 +46,7 @@ class CircleBuf public: - MD5Summation *MD5; + Hashes *Hash; // Read data in bool Read(int Fd); diff --git a/methods/rsh.cc b/methods/rsh.cc index 9e521edec..5326e5098 100644 --- a/methods/rsh.cc +++ b/methods/rsh.cc @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: rsh.cc,v 1.2 2001/02/20 07:03:18 jgg Exp $ +// $Id: rsh.cc,v 1.3 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### RSH method - Transfer files via rsh compatible program @@ -271,7 +271,7 @@ bool RSHConn::ModTime(const char *Path, time_t &Time) // --------------------------------------------------------------------- /* */ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume, - MD5Summation &MD5,bool &Missing, unsigned long Size) + Hashes &Hash,bool &Missing, unsigned long Size) { Missing = false; @@ -284,7 +284,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume, return false; if (Resume != 0) { - if (MD5.AddFD(To.Fd(),Resume) == false) { + if (Hash.AddFD(To.Fd(),Resume) == false) { _error->Errno("read","Problem hashing file"); return false; } @@ -323,7 +323,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume, } MyLen += Res; - MD5.Add(Buffer,Res); + Hash.Add(Buffer,Res); if (To.Write(Buffer,Res) == false) { Close(); @@ -428,7 +428,7 @@ bool RSHMethod::Fetch(FetchItem *Itm) } // Open the file - MD5Summation MD5; + Hashes Hash; { FileFd Fd(Itm->DestFile,FileFd::WriteAny); if (_error->PendingError() == true) @@ -441,7 +441,7 @@ bool RSHMethod::Fetch(FetchItem *Itm) FailFd = Fd.Fd(); bool Missing; - if (Server->Get(File,Fd,Res.ResumePoint,MD5,Missing,Res.Size) == false) + if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Res.Size) == false) { Fd.Close(); @@ -462,7 +462,7 @@ bool RSHMethod::Fetch(FetchItem *Itm) } Res.LastModified = FailTime; - Res.MD5Sum = MD5.Result(); + Res.MD5Sum = Hash.MD5.Result(); // Timestamp struct utimbuf UBuf; diff --git a/methods/rsh.h b/methods/rsh.h index c3f3258e9..1b3bcaea4 100644 --- a/methods/rsh.h +++ b/methods/rsh.h @@ -1,6 +1,6 @@ // -*- mode: cpp; mode: fold -*- -// Description /*{{{*/// $Id: rsh.h,v 1.2 2001/02/20 07:03:18 jgg Exp $ -// $Id: rsh.h,v 1.2 2001/02/20 07:03:18 jgg Exp $ +// Description /*{{{*/// $Id: rsh.h,v 1.3 2001/03/06 07:15:29 jgg Exp $ +// $Id: rsh.h,v 1.3 2001/03/06 07:15:29 jgg Exp $ /* ###################################################################### RSH method - Transfer files via rsh compatible program @@ -12,7 +12,7 @@ #include <string> #include <apt-pkg/strutl.h> -#include <apt-pkg/md5.h> +#include <apt-pkg/hashes.h> #include <apt-pkg/acquire-method.h> #include <apt-pkg/fileutl.h> @@ -44,7 +44,7 @@ class RSHConn bool Size(const char *Path,unsigned long &Size); bool ModTime(const char *Path, time_t &Time); bool Get(const char *Path,FileFd &To,unsigned long Resume, - MD5Summation &MD5,bool &Missing, unsigned long Size); + Hashes &Hash,bool &Missing, unsigned long Size); RSHConn(URI Srv); ~RSHConn(); |