diff options
| author | Julian Andres Klode <jak@debian.org> | 2023-05-24 13:16:41 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2023-05-24 13:16:41 +0000 |
| commit | 94a3f2abc3b39095c3539ef350dc4627bd7e576c (patch) | |
| tree | f27ac33685b8bb0d73debfcfa505f8ac0a59f38d /apt-pkg | |
| parent | 9da15d149f97e0f26cf5b7e32405512a5e63523c (diff) | |
| parent | 4000ee2f9064623e096d975489aec35c99982437 (diff) | |
Merge branch 'pu/snapshot-seed' into 'main'
Seed snapshot servers for well-known hosts
See merge request apt-team/apt!293
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/deb/debmetaindex.cc | 57 | ||||
| -rw-r--r-- | apt-pkg/init.cc | 7 |
2 files changed, 52 insertions, 12 deletions
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 4133540ab..ef6bce261 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1261,9 +1261,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ #define APT_EMPTY_SERVER \ if (server.empty() == false) \ { \ - if (server != "no") \ - return server; \ - return ""; \ + return server; \ } #define APT_CHECK_SERVER(X, Y) \ if (not Rls->Get##X().empty()) \ @@ -1285,6 +1283,16 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ #undef APT_EMPTY_SERVER return ""; } + + /// \brief Given a hostname, strip one level down, e.g. a.b.c -> .b.c -> .c, this + /// allows you to match a.b.c against itself, .b.c, and .c, but not b.c + static inline std::string NextLevelDomain(std::string Host) + { + auto nextDot = Host.find(".", 1); + if (nextDot == Host.npos) + return ""; + return Host.substr(nextDot); + } bool CreateItemInternal(std::vector<metaIndex *> &List, std::string URI, std::string const &Dist, std::string const &Section, bool const &IsSrc, std::map<std::string, std::string> Options) const @@ -1295,20 +1303,45 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ Options.emplace("SHADOWED", "true"); + ::URI ArchiveURI(URI); + // Trim trailing and leading / from the path because we don't want them when calculating snapshot url + if (not ArchiveURI.Path.empty() && ArchiveURI.Path[ArchiveURI.Path.length() - 1] == '/') + ArchiveURI.Path.erase(ArchiveURI.Path.length() - 1); + if (not ArchiveURI.Path.empty() && ArchiveURI.Path[0] == '/') + ArchiveURI.Path.erase(0, 1); + std::string Server; + auto const Deb = GetDebReleaseIndexBy(List, URI, Dist, Options); std::string filename; - if (not ReleaseFileName(Deb, filename)) - return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); - auto OldDeb = dynamic_cast<debReleaseIndex *>(Deb->UnloadedClone()); - if (not OldDeb->Load(filename, nullptr)) - return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); - auto Server = SnapshotServer(OldDeb); - delete OldDeb; + // The Release file and config based on that should be the ultimate source of truth. + if (ReleaseFileName(Deb, filename)) + { + auto OldDeb = dynamic_cast<debReleaseIndex *>(Deb->UnloadedClone()); + if (not OldDeb->Load(filename, nullptr)) + return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); + Server = SnapshotServer(OldDeb); + delete OldDeb; + } + // We did not find a server based on the release file. + // Lookup a fallback based on the host. For a.b.c, this will + // try a.b.c, .b.c, and .c to allow generalization for cc.archive.ubuntu.com if (Server.empty()) + { + for (std::string Host = ArchiveURI.Host; not Host.empty(); Host = NextLevelDomain(Host)) + { + Server = _config->Find("Acquire::Snapshots::URI::Host::" + Host); + if (not Server.empty()) + break; + } + } + if (Server.empty() || Server == "no") + { + if (Server != "no" && filename.empty()) + return _error->Error("Cannot identify snapshot server for %s %s - run update without snapshot id first", URI.c_str(), Dist.c_str()); return _error->Error("Snapshots not supported for %s %s", URI.c_str(), Dist.c_str()); - - auto SnapshotURI = SubstVar(Server, "@SNAPSHOTID@", Snapshot); + } + auto SnapshotURI = SubstVar(SubstVar(Server, "@SNAPSHOTID@", Snapshot), "@PATH@", ArchiveURI.Path); if (not CreateItemInternalOne(List, SnapshotURI, Dist, Section, IsSrc, SnapshotOptions)) return false; diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index f70dbf308..3990a1f39 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -212,6 +212,13 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.CndSet("Acquire::Snapshots::URI::Origin::Debian", "https://snapshot.debian.org/archive/debian/@SNAPSHOTID@/"); Cnf.CndSet("Acquire::Snapshots::URI::Override::Label::Debian-Security", "https://snapshot.debian.org/archive/debian-security/@SNAPSHOTID@/"); Cnf.CndSet("Acquire::Snapshots::URI::Origin::Ubuntu", "https://snapshot.ubuntu.com/ubuntu/@SNAPSHOTID@/"); + // Preseeds by host + Cnf.CndSet("Acquire::Snapshots::URI::Host::archive.ubuntu.com", "https://snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::deb.debian.org", "https://snapshot.debian.org/archive/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::.archive.ubuntu.com", "https://snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::security.ubuntu.com", "https://snapshot.ubuntu.com/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::ppa.launchpadcontent.net", "https://snapshot.ppa.launchpadcontent.net/@PATH@/@SNAPSHOTID@/"); + Cnf.CndSet("Acquire::Snapshots::URI::Host::ppa.launchpad.net", "https://snapshot.ppa.launchpadcontent.net/@PATH@/@SNAPSHOTID@/"); Cnf.CndSet("DPkg::Path", "/usr/sbin:/usr/bin:/sbin:/bin"); |
