X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/b0f4b486e6850c5f98520ccf19da71d0ed748ae4..ce1f3a2c616b86da657c1c796efa5f4d18c30c39:/methods/copy.cc diff --git a/methods/copy.cc b/methods/copy.cc index 40f8f85ec..373ad3604 100644 --- a/methods/copy.cc +++ b/methods/copy.cc @@ -27,22 +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) { - Hashes Hash; - FileFd::CompressMode CompressMode = FileFd::None; - if (_config->FindB("Acquire::GzipIndexes", false) == true) - CompressMode = FileFd::Extension; - - FileFd Fd(Res.Filename, FileFd::ReadOnly, CompressMode); + Hashes Hash(Itm->ExpectedHashes); + FileFd Fd(Res.Filename, FileFd::ReadOnly); Hash.AddFD(Fd); Res.TakeHashes(Hash); } @@ -53,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; @@ -65,13 +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); - + // just calc the hashes if the source and destination are identical - if (File == Itm->DestFile) + if (File == Itm->DestFile || Itm->DestFile == "/dev/null") { - CalculateHashes(Res); + CalculateHashes(Itm, Res); URIDone(Res); return true; } @@ -104,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; @@ -116,5 +112,6 @@ int main() setlocale(LC_ALL, ""); CopyMethod Mth; + return Mth.Run(); }