X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/e31a89e668596ea86c8f3a08429cd2f48286e734..f3f06cae53d8ed5742f47de46d9f9808cfc5ec29:/methods/copy.cc?ds=sidebyside diff --git a/methods/copy.cc b/methods/copy.cc index faf330ace..0c9f322e6 100644 --- a/methods/copy.cc +++ b/methods/copy.cc @@ -27,25 +27,18 @@ class CopyMethod : public pkgAcqMethod { - virtual bool Fetch(FetchItem *Itm); - void CalculateHashes(FetchResult &Res); + virtual bool Fetch(FetchItem *Itm) APT_OVERRIDE; + void CalculateHashes(FetchItem const * const Itm, FetchResult &Res); public: CopyMethod() : pkgAcqMethod("1.0",SingleInstance | SendConfig) {}; }; -void CopyMethod::CalculateHashes(FetchResult &Res) +void CopyMethod::CalculateHashes(FetchItem const * const Itm, FetchResult &Res) { - // For gzip indexes we need to look inside the gzip for the hash - // We can not use the extension here as its not used in partial - // on a IMS hit - FileFd::OpenMode OpenMode = FileFd::ReadOnly; - if (_config->FindB("Acquire::GzipIndexes", false) == true) - OpenMode = FileFd::ReadOnlyGzip; - - Hashes Hash; - FileFd Fd(Res.Filename, OpenMode); + Hashes Hash(Itm->ExpectedHashes); + FileFd Fd(Res.Filename, FileFd::ReadOnly, FileFd::Extension); Hash.AddFD(Fd); Res.TakeHashes(Hash); } @@ -56,7 +49,7 @@ void CopyMethod::CalculateHashes(FetchResult &Res) bool CopyMethod::Fetch(FetchItem *Itm) { // this ensures that relative paths work in copy - std::string File = Itm->Uri.substr(Itm->Uri.find(':')+1); + std::string const File = Itm->Uri.substr(Itm->Uri.find(':')+1); // Stat the file and send a start message struct stat Buf; @@ -68,21 +61,13 @@ bool CopyMethod::Fetch(FetchItem *Itm) Res.Size = Buf.st_size; Res.Filename = Itm->DestFile; Res.LastModified = Buf.st_mtime; - Res.IMSHit = false; + Res.IMSHit = false; URIStart(Res); - // when the files are identical, just compute the hashes - if(File == Itm->DestFile) - { - CalculateHashes(Res); - URIDone(Res); - return true; - } - // just calc the hashes if the source and destination are identical if (File == Itm->DestFile) { - CalculateHashes(Res); + CalculateHashes(Itm, Res); URIDone(Res); return true; } @@ -115,7 +100,7 @@ bool CopyMethod::Fetch(FetchItem *Itm) if (utimes(Res.Filename.c_str(), times) != 0) return _error->Errno("utimes",_("Failed to set modification time")); - CalculateHashes(Res); + CalculateHashes(Itm, Res); URIDone(Res); return true; @@ -128,6 +113,5 @@ int main() CopyMethod Mth; - Mth.DropPrivsOrDie(); return Mth.Run(); }