diff options
| author | Julian Andres Klode <jak@debian.org> | 2024-02-20 18:26:44 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2024-02-20 18:26:44 +0000 |
| commit | 6f9a11770d9ff8dff7f7bd52d03ebd2a3f4917a6 (patch) | |
| tree | aedac15f52ac6b20151ecf830f147af313d04b93 /apt-pkg | |
| parent | e3ba17fa7a60aa5cd699b69adf3989319935c917 (diff) | |
| parent | 78c3ad795de7f14de3ee22e9f04fe24b5f21f0ea (diff) | |
Merge branch 'auto-snapshot' into 'main'
Automatically enable snapshots where supported
See merge request apt-team/apt!328
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/deb/debmetaindex.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index 0f05cb21a..515893133 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -17,6 +17,7 @@ #include <apt-pkg/tagfile.h> #include <algorithm> +#include <cassert> #include <map> #include <optional> #include <sstream> @@ -1299,7 +1300,8 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ std::string const &Dist, std::string const &Section, bool const &IsSrc, std::map<std::string, std::string> Options) const { - auto Snapshot = GetSnapshotOption(Options, "snapshot"); + std::string SnapshotAptConf = _config->Find("APT::Snapshot"); + std::string Snapshot = GetSnapshotOption(Options, "snapshot", SnapshotAptConf.empty() ? "" : SnapshotAptConf + "?"); if (not Snapshot.empty()) { std::map<std::string, std::string> SnapshotOptions = Options; @@ -1313,6 +1315,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ ArchiveURI.Path.erase(0, 1); std::string Server; + auto const PreviousDeb = List.empty() ? nullptr : List.back(); auto const Deb = GetDebReleaseIndexBy(List, URI, Dist, Options); std::string filename; @@ -1339,15 +1342,34 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/ } if (Server.empty() || Server == "no") { + if (APT::String::Endswith(Snapshot, "?")) + { + // Erase the SHADOWED option and remove the release index from the list if we created it. + Options.erase("SHADOWED"); + if (Deb && Deb != PreviousDeb) { + assert(List.back() == Deb); + List.pop_back(); + delete Deb; + } + goto nosnapshot; + } 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()); } + // We have found a server by now, so we enable snapshots for this source. + if (APT::String::Endswith(Snapshot, "?")) + { + Snapshot.pop_back(); + } + + assert(not Snapshot.empty()); auto SnapshotURI = SubstVar(SubstVar(Server, "@SNAPSHOTID@", Snapshot), "@PATH@", ArchiveURI.Path); if (not CreateItemInternalOne(List, SnapshotURI, Dist, Section, IsSrc, SnapshotOptions)) return false; } + nosnapshot: if (not CreateItemInternalOne(List, URI, Dist, Section, IsSrc, Options)) return false; |
