From 3de9ff77a811d67632c9948a953e628ed6a2b78a Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 22 Aug 2005 10:19:43 +0000 Subject: [PATCH] * bugfix/updates in the rred.cc code (big thanks for helping Robert!) --- apt-pkg/acquire-item.cc | 4 ++++ debian/changelog | 2 +- methods/rred.cc | 44 ++++++++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 43d29c737..b8886a750 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -255,6 +255,7 @@ void pkgAcqIndexDiffs::Finish(bool allDone) bool pkgAcqIndexDiffs::QueueNextDiff() { + // calc sha1 of the just patched file string FinalFile = _config->FindDir("Dir::State::lists"); FinalFile += URItoFileName(RealURI); @@ -263,6 +264,9 @@ bool pkgAcqIndexDiffs::QueueNextDiff() SHA1Summation SHA1; SHA1.AddFD(fd.Fd(), fd.Size()); string local_sha1 = string(SHA1.Result()); + if(Debug) + std::clog << "QueueNextDiff: " + << FinalFile << " (" << local_sha1 << ")"< 0) { while (fgets(buffer, BUF_SIZE, in_file) != NULL) { written = fwrite(buffer, 1, strlen(buffer), out_file); - // XXX add to hash - // sha_process_bytes(buffer, written, &sha); + hash->Add((unsigned char*)buffer, written); } } else { @@ -163,7 +164,7 @@ int ed_file(FILE *ed_cmds, FILE *in_file, FILE *out_file, Hashes *hash) { fprintf(stderr, "Error: %i\n", result); return ED_FAILURE; } - return 0; + return ED_OK; } @@ -192,13 +193,38 @@ bool RredMethod::Fetch(FetchItem *Itm) FILE* fPatch = fdopen(Patch.Fd(), "r"); FILE* fTo = fdopen(To.Fd(), "w"); // now do the actual patching - ed_file(fPatch, fFrom, fTo, &Hash); - - // XXX need to get the size - // Res.Size = Buf.st_size; + if (ed_file(fPatch, fFrom, fTo, &Hash) != ED_OK) { + return false; + } + + // write out the result + fflush(fFrom); + fflush(fPatch); + fflush(fTo); + From.Close(); + Patch.Close(); + To.Close(); + + // Transfer the modification times + struct stat Buf; + if (stat(Path.c_str(),&Buf) != 0) + return _error->Errno("stat",_("Failed to stat")); + + struct utimbuf TimeBuf; + TimeBuf.actime = Buf.st_atime; + TimeBuf.modtime = Buf.st_mtime; + if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0) + return _error->Errno("utime",_("Failed to set modification time")); + + if (stat(Itm->DestFile.c_str(),&Buf) != 0) + return _error->Errno("stat",_("Failed to stat")); + + // return done + Res.LastModified = Buf.st_mtime; + Res.Size = Buf.st_size; Res.TakeHashes(Hash); URIDone(Res); - + return true; } /*}}}*/ -- 2.45.2