X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/cc0f9c8e1044335f167b6b87d71dc91dd2f3501b..6f976e5dd7ccc27d48b6a000fed0c553bd017d34:/methods/rred.cc?ds=inline diff --git a/methods/rred.cc b/methods/rred.cc index c2d8eb5cf..d51c45c85 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -229,7 +229,6 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/ #ifdef _POSIX_MAPPED_FILES MMap ed_cmds(Patch, MMap::ReadOnly); MMap in_file(From, MMap::ReadOnly); - FILE* fTo = fdopen(out_file.Fd(), "w"); if (ed_cmds.Size() == 0 || in_file.Size() == 0) return MMAP_FAILED; @@ -420,8 +419,6 @@ RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/ delete [] iov; free(commands); - fflush(fTo); - return ED_OK; #else return MMAP_FAILED; @@ -449,7 +446,7 @@ bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/ // the cleanup/closing of the fds) FileFd From(Path,FileFd::ReadOnly); FileFd Patch(Path+".ed",FileFd::ReadOnly); - FileFd To(Itm->DestFile,FileFd::WriteEmpty); + FileFd To(Itm->DestFile,FileFd::WriteAtomic); To.EraseOnFailure(); if (_error->PendingError() == true) return false; @@ -461,14 +458,18 @@ bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/ // retry with patchFile lseek(Patch.Fd(), 0, SEEK_SET); lseek(From.Fd(), 0, SEEK_SET); - To.Open(Itm->DestFile,FileFd::WriteEmpty); + To.Open(Itm->DestFile,FileFd::WriteAtomic); if (_error->PendingError() == true) return false; if (patchFile(Patch, From, To, &Hash) != ED_OK) { - return _error->Errno("rred", _("Could not patch file %s"), Path.append(" (1)").c_str()); + return _error->WarningE("rred", _("Could not patch %s with mmap and with file operation usage - the patch seems to be corrupt."), Path.c_str()); + } else if (Debug == true) { + std::clog << "rred: finished file patching of " << Path << " after mmap failed." << std::endl; } } else if (result != ED_OK) { - return _error->Errno("rred", _("Could not patch file %s"), Path.append(" (2)").c_str()); + return _error->Errno("rred", _("Could not patch %s with mmap (but no mmap specific fail) - the patch seems to be corrupt."), Path.c_str()); + } else if (Debug == true) { + std::clog << "rred: finished mmap patching of " << Path << std::endl; } // write out the result @@ -476,27 +477,28 @@ bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/ Patch.Close(); To.Close(); - // Transfer the modification times - struct stat Buf; - if (stat(Path.c_str(),&Buf) != 0) + /* Transfer the modification times from the patch file + to be able to see in which state the file should be + and use the access time from the "old" file */ + struct stat BufBase, BufPatch; + if (stat(Path.c_str(),&BufBase) != 0 || + stat(string(Path+".ed").c_str(),&BufPatch) != 0) return _error->Errno("stat",_("Failed to stat")); struct utimbuf TimeBuf; - TimeBuf.actime = Buf.st_atime; - TimeBuf.modtime = Buf.st_mtime; + TimeBuf.actime = BufBase.st_atime; + TimeBuf.modtime = BufPatch.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) + if (stat(Itm->DestFile.c_str(),&BufBase) != 0) return _error->Errno("stat",_("Failed to stat")); // return done - if (Itm->Uri.empty() == true) { - Res.LastModified = Buf.st_mtime; - Res.Size = Buf.st_size; - Res.TakeHashes(Hash); - URIDone(Res); - } + Res.LastModified = BufBase.st_mtime; + Res.Size = BufBase.st_size; + Res.TakeHashes(Hash); + URIDone(Res); return true; }