Просмотр исходного кода

* use the new cool rred method for the patchting

Michael Vogt лет назад: 21
Родитель
Сommit
4a0a786f45
4 измененных файлов с 69 добавлено и 50 удалено
  1. 65 47
      apt-pkg/acquire-item.cc
  2. 2 1
      apt-pkg/acquire-item.h
  3. 1 1
      methods/makefile
  4. 1 1
      methods/rred.cc

+ 65 - 47
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();
 }
 
 

+ 2 - 1
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:
    

+ 1 - 1
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

+ 1 - 1
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);