From: Michael Vogt Date: Wed, 9 Jun 2010 10:08:54 +0000 (+0200) Subject: merge lp:~mvo/apt/ubuntu-mirror-method-improvements X-Git-Tag: 0.8.0~9^2~41 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/e7aea3985734af1702fde6e2b0af90b992425334?ds=inline;hp=-c merge lp:~mvo/apt/ubuntu-mirror-method-improvements --- e7aea3985734af1702fde6e2b0af90b992425334 diff --combined apt-pkg/acquire-item.cc index bb8a01db8,3cc2c8717..8973eedde --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@@ -81,7 -81,7 +81,7 @@@ void pkgAcquire::Item::Failed(string Me Status = StatError; Dequeue(); } - + // report mirror failure back to LP if we actually use a mirror string FailReason = LookupTag(Message, "FailReason"); if(FailReason.size() != 0) @@@ -360,7 -360,7 +360,7 @@@ bool pkgAcqDiffIndex::ParseDiffIndex(st if(last_space != string::npos) Description.erase(last_space, Description.size()-last_space); new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc, - ExpectedHash, available_patches); + ExpectedHash, ServerSha1, available_patches); Complete = false; Status = StatDone; Dequeue(); @@@ -428,10 -428,9 +428,10 @@@ void pkgAcqDiffIndex::Done(string Messa pkgAcqIndexDiffs::pkgAcqIndexDiffs(pkgAcquire *Owner, string URI,string URIDesc,string ShortDesc, HashString ExpectedHash, + string ServerSha1, vector diffs) : Item(Owner), RealURI(URI), ExpectedHash(ExpectedHash), - available_patches(diffs) + available_patches(diffs), ServerSha1(ServerSha1) { DestFile = _config->FindDir("Dir::State::lists") + "partial/"; @@@ -517,13 -516,6 +517,13 @@@ bool pkgAcqIndexDiffs::QueueNextDiff( std::clog << "QueueNextDiff: " << FinalFile << " (" << local_sha1 << ")"<::iterator I=available_patches.begin(); @@@ -621,7 -613,7 +621,7 @@@ void pkgAcqIndexDiffs::Done(string Mess // see if there is more to download if(available_patches.size() > 0) { new pkgAcqIndexDiffs(Owner, RealURI, Description, Desc.ShortDesc, - ExpectedHash, available_patches); + ExpectedHash, ServerSha1, available_patches); return Finish(); } else return Finish(true); @@@ -828,6 -820,13 +828,13 @@@ pkgAcqIndexTrans::pkgAcqIndexTrans(pkgA string URI,string URIDesc,string ShortDesc) : pkgAcqIndex(Owner, URI, URIDesc, ShortDesc, HashString(), "") { + } + /*}}}*/ + // AcqIndexTrans::Custom600Headers - Insert custom request headers /*{{{*/ + // --------------------------------------------------------------------- + string pkgAcqIndexTrans::Custom600Headers() + { + return "\nFail-Ignore: true"; } /*}}}*/ // AcqIndexTrans::Failed - Silence failure messages for missing files /*{{{*/ @@@ -1160,7 -1159,7 +1167,7 @@@ void pkgAcqMetaIndex::QueueIndexes(boo // Queue Packages file (either diff or full packages files, depending // on the users option) - if(_config->FindB("Acquire::PDiffs",false) == true) + if(_config->FindB("Acquire::PDiffs", true) == true) new pkgAcqDiffIndex(Owner, (*Target)->URI, (*Target)->Description, (*Target)->ShortDesc, ExpectedIndexHash); else @@@ -1379,8 -1378,7 +1386,8 @@@ pkgAcqArchive::pkgAcqArchive(pkgAcquir the archive is already available in the cache and stashs the MD5 for checking later. */ bool pkgAcqArchive::QueueNext() -{ +{ + string const ForceHash = _config->Find("Acquire::ForceHash"); for (; Vf.end() == false; Vf++) { // Ignore not source sources @@@ -1403,25 -1401,12 +1410,25 @@@ return false; string PkgFile = Parse.FileName(); - if(Parse.SHA256Hash() != "") - ExpectedHash = HashString("SHA256", Parse.SHA256Hash()); - else if (Parse.SHA1Hash() != "") - ExpectedHash = HashString("SHA1", Parse.SHA1Hash()); - else - ExpectedHash = HashString("MD5Sum", Parse.MD5Hash()); + if (ForceHash.empty() == false) + { + if(stringcasecmp(ForceHash, "sha256") == 0) + ExpectedHash = HashString("SHA256", Parse.SHA256Hash()); + else if (stringcasecmp(ForceHash, "sha1") == 0) + ExpectedHash = HashString("SHA1", Parse.SHA1Hash()); + else + ExpectedHash = HashString("MD5Sum", Parse.MD5Hash()); + } + else + { + string Hash; + if ((Hash = Parse.SHA256Hash()).empty() == false) + ExpectedHash = HashString("SHA256", Hash); + else if ((Hash = Parse.SHA1Hash()).empty() == false) + ExpectedHash = HashString("SHA1", Hash); + else + ExpectedHash = HashString("MD5Sum", Parse.MD5Hash()); + } if (PkgFile.empty() == true) return _error->Error(_("The package index files are corrupted. No Filename: " "field for package %s."), @@@ -1613,9 -1598,8 +1620,9 @@@ void pkgAcqArchive::Finished( /* The file is added to the queue */ pkgAcqFile::pkgAcqFile(pkgAcquire *Owner,string URI,string Hash, unsigned long Size,string Dsc,string ShortDesc, - const string &DestDir, const string &DestFilename) : - Item(Owner), ExpectedHash(Hash) + const string &DestDir, const string &DestFilename, + bool IsIndexFile) : + Item(Owner), ExpectedHash(Hash), IsIndexFile(IsIndexFile) { Retries = _config->FindI("Acquire::Retries",0); @@@ -1730,13 -1714,3 +1737,13 @@@ void pkgAcqFile::Failed(string Message, Item::Failed(Message,Cnf); } /*}}}*/ +// AcqIndex::Custom600Headers - Insert custom request headers /*{{{*/ +// --------------------------------------------------------------------- +/* The only header we use is the last-modified header. */ +string pkgAcqFile::Custom600Headers() +{ + if (IsIndexFile) + return "\nIndex-File: true"; + return ""; +} + /*}}}*/ diff --combined apt-pkg/acquire-item.h index 332df5a6b,3ac8a19e2..8f35c0dbf --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@@ -27,7 -27,6 +27,7 @@@ #include #include #include +#include /** \addtogroup acquire * @{ @@@ -47,7 -46,7 +47,7 @@@ * * \see pkgAcquire */ -class pkgAcquire::Item +class pkgAcquire::Item : public WeakPointable { protected: @@@ -435,10 -434,6 +435,10 @@@ class pkgAcqIndexDiffs : public pkgAcqu * off the front? */ vector available_patches; + + /** Stop applying patches when reaching that sha1 */ + string ServerSha1; + /** The current status of this patch. */ enum DiffState { @@@ -492,7 -487,6 +492,7 @@@ */ pkgAcqIndexDiffs(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc, HashString ExpectedHash, + string ServerSha1, vector diffs=vector()); }; /*}}}*/ @@@ -579,6 -573,7 +579,7 @@@ class pkgAcqIndexTrans : public pkgAcqI public: virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); + virtual string Custom600Headers(); /** \brief Create a pkgAcqIndexTrans. * @@@ -874,9 -869,6 +875,9 @@@ class pkgAcqFile : public pkgAcquire::I */ unsigned int Retries; + /** \brief Should this file be considered a index file */ + bool IsIndexFile; + public: // Specialized action members @@@ -885,7 -877,6 +886,7 @@@ pkgAcquire::MethodConfig *Cnf); virtual string DescURI() {return Desc.URI;}; virtual string HashSum() {return ExpectedHash.toStr(); }; + virtual string Custom600Headers(); /** \brief Create a new pkgAcqFile object. * @@@ -909,8 -900,6 +910,8 @@@ * * \param DestFilename The filename+path the file is downloaded to. * + * \param IsIndexFile The file is considered a IndexFile and cache-control + * headers like "cache-control: max-age=0" are send * * If DestFilename is empty, download to DestDir/ if * DestDir is non-empty, $CWD/ otherwise. If @@@ -920,8 -909,7 +921,8 @@@ pkgAcqFile(pkgAcquire *Owner, string URI, string Hash, unsigned long Size, string Desc, string ShortDesc, - const string &DestDir="", const string &DestFilename=""); + const string &DestDir="", const string &DestFilename="", + bool IsIndexFile=false); }; /*}}}*/ /** @} */ diff --combined apt-pkg/deb/dpkgpm.cc index c724c69a9,7e5171eda..95e3bafdc --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@@ -21,6 -21,7 +21,7 @@@ #include #include #include + #include #include #include #include @@@ -52,7 -53,6 +53,7 @@@ namespac std::make_pair("configure", N_("Configuring %s")), std::make_pair("remove", N_("Removing %s")), std::make_pair("purge", N_("Completely removing %s")), + std::make_pair("disappear", N_("Noting disappearance of %s")), std::make_pair("trigproc", N_("Running post-installation trigger %s")) }; @@@ -108,7 -108,7 +109,7 @@@ ionice(int PID /* */ pkgDPkgPM::pkgDPkgPM(pkgDepCache *Cache) : pkgPackageManager(Cache), dpkgbuf_pos(0), - term_out(NULL), PackagesDone(0), PackagesTotal(0), pkgFailures(0) + term_out(NULL), history_out(NULL), PackagesDone(0), PackagesTotal(0) { } /*}}}*/ @@@ -127,19 -127,7 +128,19 @@@ bool pkgDPkgPM::Install(PkgIterator Pkg if (File.empty() == true || Pkg.end() == true) return _error->Error("Internal Error, No file name for %s",Pkg.Name()); - List.push_back(Item(Item::Install,Pkg,File)); + // If the filename string begins with DPkg::Chroot-Directory, return the + // substr that is within the chroot so dpkg can access it. + string const chrootdir = _config->FindDir("DPkg::Chroot-Directory","/"); + if (chrootdir != "/" && File.find(chrootdir) == 0) + { + size_t len = chrootdir.length(); + if (chrootdir.at(len - 1) == '/') + len--; + List.push_back(Item(Item::Install,Pkg,File.substr(len))); + } + else + List.push_back(Item(Item::Install,Pkg,File)); + return true; } /*}}}*/ @@@ -421,8 -409,7 +422,8 @@@ void pkgDPkgPM::ProcessDpkgStatusLine(i 'processing: install: pkg' 'processing: configure: pkg' 'processing: remove: pkg' - 'processing: purge: pkg' - but for apt is it a ignored "unknown" action + 'processing: purge: pkg' + 'processing: disappear: pkg' 'processing: trigproc: trigger' */ @@@ -469,9 -456,6 +470,9 @@@ write(OutStatusFd, status.str().c_str(), status.str().size()); if (Debug == true) std::clog << "send: '" << status.str() << "'" << endl; + + if (strncmp(action, "disappear", strlen("disappear")) == 0) + disappearedPkgs.insert(string(pkg_or_trigger)); return; } @@@ -579,7 -563,7 +580,7 @@@ void pkgDPkgPM::DoDpkgStatusFd(int stat } /*}}}*/ // DPkgPM::WriteHistoryTag /*{{{*/ -void pkgDPkgPM::WriteHistoryTag(FILE *history_out, string tag, string value) +void pkgDPkgPM::WriteHistoryTag(string tag, string value) { if (value.size() > 0) { @@@ -620,7 -604,7 +621,7 @@@ bool pkgDPkgPM::OpenLog( _config->Find("Dir::Log::History")); if (!history_name.empty()) { - FILE *history_out = fopen(history_name.c_str(),"a"); + history_out = fopen(history_name.c_str(),"a"); if (history_out == NULL) return _error->WarningE("OpenLog", _("Could not open file '%s'"), history_name.c_str()); chmod(history_name.c_str(), 0644); @@@ -642,14 -626,12 +643,14 @@@ remove += I.Name() + string(" (") + Cache[I].CurVersion + string("), "); } } - WriteHistoryTag(history_out, "Install", install); - WriteHistoryTag(history_out, "Upgrade", upgrade); - WriteHistoryTag(history_out, "Downgrade",downgrade); - WriteHistoryTag(history_out, "Remove",remove); - WriteHistoryTag(history_out, "Purge",purge); - fclose(history_out); + if (_config->Exists("Commandline::AsString") == true) + WriteHistoryTag("Commandline", _config->Find("Commandline::AsString")); + WriteHistoryTag("Install", install); + WriteHistoryTag("Upgrade", upgrade); + WriteHistoryTag("Downgrade",downgrade); + WriteHistoryTag("Remove",remove); + WriteHistoryTag("Purge",purge); + fflush(history_out); } return true; @@@ -672,14 -654,14 +673,14 @@@ bool pkgDPkgPM::CloseLog( } term_out = NULL; - string history_name = flCombine(_config->FindDir("Dir::Log"), - _config->Find("Dir::Log::History")); - if (!history_name.empty()) + if(history_out) { - FILE *history_out = fopen(history_name.c_str(),"a"); + if (dpkg_error.size() > 0) + fprintf(history_out, "Error: %s\n", dpkg_error.c_str()); fprintf(history_out, "End-Date: %s\n", timestr); fclose(history_out); } + history_out = NULL; return true; } @@@ -927,8 -909,6 +928,8 @@@ bool pkgDPkgPM::Go(int OutStatusFd { if((*I).Pkg.end() == true) continue; + if (I->Op == Item::Configure && disappearedPkgs.find(I->Pkg.Name()) != disappearedPkgs.end()) + continue; Args[n++] = I->Pkg.Name(); Size += strlen(Args[n-1]); } @@@ -1096,10 -1076,9 +1097,10 @@@ signal(SIGHUP,old_SIGHUP); return _error->Errno("waitpid","Couldn't wait for subprocess"); } + // wait for input or output here FD_ZERO(&rfds); - if (!stdin_is_dev_null) + if (master >= 0 && !stdin_is_dev_null) FD_SET(0, &rfds); FD_SET(_dpkgin, &rfds); if(master >= 0) @@@ -1152,6 -1131,7 +1153,6 @@@ if(stopOnError) RunScripts("DPkg::Post-Invoke"); - string dpkg_error; if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV) strprintf(dpkg_error, "Sub-process %s received a segmentation fault.",Args[0]); else if (WIFEXITED(Status) != 0) @@@ -1160,7 -1140,17 +1161,7 @@@ strprintf(dpkg_error, "Sub-process %s exited unexpectedly",Args[0]); if(dpkg_error.size() > 0) - { _error->Error(dpkg_error.c_str()); - string history_name = flCombine(_config->FindDir("Dir::Log"), - _config->Find("Dir::Log::History")); - if (!history_name.empty()) - { - FILE *history_out = fopen(history_name.c_str(),"a"); - fprintf(history_out, "Error: %s\n", dpkg_error.c_str()); - fclose(history_out); - } - } if(stopOnError) { @@@ -1195,7 -1185,7 +1196,7 @@@ void pkgDPkgPM::WriteApportReport(cons string::size_type pos; FILE *report; - if (_config->FindB("Dpkg::ApportFailureReport",true) == false) + if (_config->FindB("Dpkg::ApportFailureReport", false) == false) { std::clog << "configured to not write apport reports" << std::endl; return;