diff options
Diffstat (limited to 'apt-pkg/deb')
| -rw-r--r-- | apt-pkg/deb/debmetaindex.cc | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 4133540ab..ddc246349 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -1295,20 +1295,42 @@ 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; + } if (Server.empty()) + { + // 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 + for (std::string Host = ArchiveURI.Host; not Host.empty() && Server.empty(); Host = Host.find(".", 1) != Host.npos ? Host.substr(Host.find(".", 1)) : "") + Server = _config->Find("Acquire::Snapshots::URI::Host::" + Host); + if (Server == "no") + Server = ""; + } + if (Server.empty()) + { + if (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; |
