diff options
-rw-r--r-- | apt-pkg/acquire-item.cc | 112 | ||||
-rw-r--r-- | apt-pkg/acquire-item.h | 3 | ||||
-rw-r--r-- | methods/makefile | 2 | ||||
-rw-r--r-- | methods/rred.cc | 2 |
4 files changed, 69 insertions, 50 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 79e0b1898..166845868 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -141,8 +141,9 @@ void pkgAcquire::Item::Rename(string From,string To) */ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, string URI,string URIDesc,string ShortDesc, - string ExpectedMD5, vector<DiffInfo> diffs) - : Item(Owner), RealURI(URI), ExpectedMD5(ExpectedMD5), available_patches(diffs) + string ExpectedMD5, vector<DiffInfo> diffs) + : Item(Owner), RealURI(URI), ExpectedMD5(ExpectedMD5), + available_patches(diffs) { DestFile = _config->FindDir("Dir::State::lists") + "partial/"; @@ -171,10 +172,13 @@ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, return; } - if(available_patches.size() == 0) + if(available_patches.size() == 0) { + State = StateFetchIndex; QueueDiffIndex(URI); - else + } else { + State = StateFetchDiff; QueueNextDiff(); + } } void pkgAcqIndexDiffs::QueueDiffIndex(string URI) @@ -195,7 +199,8 @@ void pkgAcqIndexDiffs::QueueDiffIndex(string URI) /* The only header we use is the last-modified header. */ string pkgAcqIndexDiffs::Custom600Headers() { - if(DestFile.rfind(".IndexDiff") == string::npos) + // we only care for the IndexDiff file + if(State != StateFetchIndex) return string(""); string Final = _config->FindDir("Dir::State::lists"); @@ -248,33 +253,6 @@ void pkgAcqIndexDiffs::Finish(bool allDone) } -// this needs to be rewriten to not depend on the external ed -bool pkgAcqIndexDiffs::ApplyDiff(string PatchFile) -{ - char *error; - int res=0; - - string FinalFile = _config->FindDir("Dir::State::lists"); - FinalFile += URItoFileName(RealURI); - - int Process = ExecFork(); - if (Process == 0) - { - chdir(_config->FindDir("Dir::State::lists").c_str()); - // for some reason "red" fails with the pdiffs from p.d.o/~aba ?!? - string cmd = "(zcat " + PatchFile + "; echo \"wq\" ) | /bin/ed " + FinalFile + " >/dev/null 2>/dev/null"; - if(Debug) - std::clog << "Runing: " << cmd << std::endl; - res = system(cmd.c_str()); - _exit(WEXITSTATUS(res)); - } - if(!ExecWait(Process, error, true)) { - //_error->Error("Patch failed: %s ", error); - return false; - } - - return true; -} bool pkgAcqIndexDiffs::QueueNextDiff() { @@ -393,13 +371,14 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long Size,string Md5Hash, Item::Done(Message,Size,Md5Hash,Cnf); - int len = Desc.URI.size(); - // sucess in downloading the index - if(Desc.URI.substr(len-strlen("Index"),len-1) == "Index") { + string FinalFile; + FinalFile = _config->FindDir("Dir::State::lists")+URItoFileName(RealURI); - // rename - string FinalFile = _config->FindDir("Dir::State::lists"); - FinalFile += URItoFileName(RealURI) + string(".IndexDiff"); + // sucess in downloading the index + if(State == StateFetchIndex) + { + // rename the index + FinalFile += string(".IndexDiff"); if(Debug) std::clog << "Renaming: " << DestFile << " -> " << FinalFile << std::endl; @@ -413,21 +392,60 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long Size,string Md5Hash, return Finish(); } - // sucess in downloading a diff - if(Desc.URI.find(".diff") != string::npos) { - ApplyDiff(DestFile); + // sucess in downloading a diff, enter ApplyDiff state + if(State == StateFetchDiff) + { + + if(Debug) + std::clog << "Sending to gzip method: " << FinalFile << std::endl; + + string FileName = LookupTag(Message,"Filename"); + State = StateUnzipDiff; + Desc.URI = "gzip:" + FileName; + DestFile += ".decomp"; + QueueURI(Desc); + Mode = "gzip"; + return; + } + + // sucess in downloading a diff, enter ApplyDiff state + if(State == StateUnzipDiff) + { + + // rred excepts the patch as $FinalFile.ed + Rename(DestFile,FinalFile+".ed"); + + if(Debug) + std::clog << "Sending to rred method: " << FinalFile << std::endl; + + State = StateApplyDiff; + Desc.URI = "rred:" + FinalFile; + QueueURI(Desc); + Mode = "rred"; + return; + } + + + // success in download/apply a diff, queue next (if needed) + if(State == StateApplyDiff) + { + // remove the just applied patch available_patches.erase(available_patches.begin()); + // move into place + if(Debug) + std::clog << "Moving patched file in place: " << std::endl + << DestFile << " -> " << FinalFile << std::endl; + Rename(DestFile,FinalFile); + + // see if there is more to download if(available_patches.size() > 0) { new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc, ExpectedMD5, available_patches); - } else { - Finish(true); - return; - } + return Finish(); + } else + return Finish(true); } - - Finish(); } diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 8d58a39ba..99629216a 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -90,6 +90,7 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item pkgAcquire::ItemDesc Desc; string RealURI; string ExpectedMD5; + // this is the SHA-1 sum we expect after the patching string ServerSha1; string CurrentPackagesFile; @@ -100,7 +101,7 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item unsigned long size; }; vector<DiffInfo> available_patches; - + enum {StateFetchIndex,StateFetchDiff,StateUnzipDiff,StateApplyDiff} State; public: diff --git a/methods/makefile b/methods/makefile index 93ad6d875..bf8fc0dab 100644 --- a/methods/makefile +++ b/methods/makefile @@ -63,7 +63,7 @@ include $(PROGRAM_H) PROGRAM=rred SLIBS = -lapt-pkg $(SOCKETLIBS) LIB_MAKES = apt-pkg/makefile -SOURCE = rred +SOURCE = rred.cc include $(PROGRAM_H) # The rsh method diff --git a/methods/rred.cc b/methods/rred.cc index 37faab08a..e28dc6855 100644 --- a/methods/rred.cc +++ b/methods/rred.cc @@ -177,7 +177,7 @@ bool RredMethod::Fetch(FetchItem *Itm) Res.Filename = Itm->DestFile; URIStart(Res); // Res.Filename the destination filename - + // Open the source and destination files FileFd From(Path,FileFd::ReadOnly); FileFd Patch(Path+".ed",FileFd::ReadOnly); |