From 6cb30d01f8e247e85966ba8ad657453d73598527 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 7 May 2005 15:39:12 +0000 Subject: [PATCH] * use "red" now, print meaningfull pdiff names, use IMS for the IndexDiff --- apt-pkg/acquire-item.cc | 60 +++++++++++++++++++++++++++++++++-------- apt-pkg/acquire-item.h | 12 ++++++--- po/apt-all.pot | 12 ++++----- 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 8c519e3f..5d741af6 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -141,7 +141,7 @@ void pkgAcquire::Item::Rename(string From,string To) */ pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, string URI,string URIDesc,string ShortDesc, - string ExpectedMD5, vector diffs) + string ExpectedMD5, vector diffs) : Item(Owner), RealURI(URI), ExpectedMD5(ExpectedMD5), needed_files(diffs) { @@ -190,6 +190,27 @@ void pkgAcqIndexDiffs::QueueDiffIndex(string URI) QueueURI(Desc); } +// AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/ +// --------------------------------------------------------------------- +/* The only header we use is the last-modified header. */ +string pkgAcqIndexDiffs::Custom600Headers() +{ + if(DestFile.rfind(".IndexDiff") == string::npos) + return string(""); + + string Final = _config->FindDir("Dir::State::lists"); + Final += URItoFileName(RealURI) + string(".IndexDiff"); + + if(Debug) + std::clog << "Custom600Header-IMS: " << Final << std::endl; + + struct stat Buf; + if (stat(Final.c_str(),&Buf) != 0) + return "\nIndex-File: true"; + + return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime); +} + void pkgAcqIndexDiffs::Failed(string Message,pkgAcquire::MethodConfig *Cnf) { if(Debug) @@ -240,7 +261,7 @@ bool pkgAcqIndexDiffs::ApplyDiff(string PatchFile) if (Process == 0) { chdir(_config->FindDir("Dir::State::lists").c_str()); - string cmd = "(zcat " + PatchFile + "; echo \"wq\" ) | ed " + FinalFile + " >/dev/null 2>/dev/null"; + string cmd = "(zcat " + PatchFile + "; echo \"wq\" ) | red " + FinalFile + " >/dev/null 2>/dev/null"; if(Debug) std::clog << "Runing: " << cmd << std::endl; res = system(cmd.c_str()); @@ -256,12 +277,16 @@ bool pkgAcqIndexDiffs::ApplyDiff(string PatchFile) bool pkgAcqIndexDiffs::QueueNextDiff() { + // FIXME: don't use the needed_files[0] but check sha1 and search + // for the right patch in needed_files + // -> and rename needed_files to "available_patches" + // queue diff - Desc.URI = string(RealURI) + string(".diff/") + needed_files[0] + string(".gz"); - Desc.Description = Description + string("-diff"); + Desc.URI = string(RealURI) + string(".diff/") + needed_files[0].file + string(".gz"); + Desc.Description = needed_files[0].file + string(".pdiff"); DestFile = _config->FindDir("Dir::State::lists") + "partial/"; - DestFile += URItoFileName(RealURI + string(".diff/") + needed_files[0]); + DestFile += URItoFileName(RealURI + string(".diff/") + needed_files[0].file); if(Debug) std::clog << "pkgAcqIndexDiffs::QueueNextDiff(): " << Desc.URI << std::endl; @@ -306,15 +331,17 @@ bool pkgAcqIndexDiffs::ParseIndexDiff(string IndexDiffFile) // check the historie and see what patches we need string history = Tags.FindS("SHA1-History"); std::stringstream hist(history); - string sha1, size, file; + DiffInfo d; + string size; bool found = false; - while(hist >> sha1 >> size >> file) { - if(sha1 == local_sha1) + while(hist >> d.sha1 >> size >> d.file) { + d.size = atoi(size.c_str()); + if(d.sha1 == local_sha1) found=true; if(found) { if(Debug) - std::clog << "Need to get diff: " << file << std::endl; - needed_files.push_back(file); + std::clog << "Need to get diff: " << d.file << std::endl; + needed_files.push_back(d); } } // no information how to get the patches, bail out @@ -347,9 +374,20 @@ void pkgAcqIndexDiffs::Done(string Message,unsigned long Size,string Md5Hash, int len = Desc.URI.size(); // sucess in downloading the index if(Desc.URI.substr(len-strlen("Index"),len-1) == "Index") { + + // rename + string FinalFile = _config->FindDir("Dir::State::lists"); + FinalFile += URItoFileName(RealURI) + string(".IndexDiff"); + if(Debug) + std::clog << "Renaming: " << DestFile << " -> " << FinalFile + << std::endl; + Rename(DestFile,FinalFile); + chmod(FinalFile.c_str(),0644); + DestFile = FinalFile; + if(!ParseIndexDiff(DestFile)) return Failed("", NULL); - else + else return Finish(); } diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index f56fd046..6c78f33e 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -94,8 +94,14 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item string ServerSha1; string CurrentPackagesFile; string Description; - vector needed_files; + struct DiffInfo { + string file; + string sha1; + unsigned long size; + }; + vector needed_files; + public: // Specialized action members @@ -103,7 +109,7 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item virtual void Done(string Message,unsigned long Size,string Md5Hash, pkgAcquire::MethodConfig *Cnf); virtual string DescURI() {return RealURI + "Index";}; - + virtual string Custom600Headers(); // various helpers bool ParseIndexDiff(string IndexDiffFile); @@ -114,7 +120,7 @@ class pkgAcqIndexDiffs : public pkgAcquire::Item pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesct, string ExpectedMD5, - vector diffs=vector()); + vector diffs=vector()); }; // Item class for index files diff --git a/po/apt-all.pot b/po/apt-all.pot index 1715e5a4..7c3774ed 100644 --- a/po/apt-all.pot +++ b/po/apt-all.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2005-04-15 11:37+0200\n" +"POT-Creation-Date: 2005-05-07 16:22+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -2251,31 +2251,31 @@ msgstr "" msgid "rename failed, %s (%s -> %s)." msgstr "" -#: apt-pkg/acquire-item.cc:475 apt-pkg/acquire-item.cc:1134 +#: apt-pkg/acquire-item.cc:502 apt-pkg/acquire-item.cc:1161 msgid "MD5Sum mismatch" msgstr "" -#: apt-pkg/acquire-item.cc:948 +#: apt-pkg/acquire-item.cc:975 #, c-format msgid "" "I wasn't able to locate a file for the %s package. This might mean you need " "to manually fix this package. (due to missing arch)" msgstr "" -#: apt-pkg/acquire-item.cc:1001 +#: apt-pkg/acquire-item.cc:1028 #, c-format msgid "" "I wasn't able to locate file for the %s package. This might mean you need to " "manually fix this package." msgstr "" -#: apt-pkg/acquire-item.cc:1037 +#: apt-pkg/acquire-item.cc:1064 #, c-format msgid "" "The package index files are corrupted. No Filename: field for package %s." msgstr "" -#: apt-pkg/acquire-item.cc:1124 +#: apt-pkg/acquire-item.cc:1151 msgid "Size mismatch" msgstr "" -- 2.20.1