download_sets.h Header
Types
| struct | ServedSet | The downloads that a project's sidebar offers, as chosen by select_served_set. |
Type Aliases
| using | DownloadUrls | The URLs of one project's download rows, in config order. |
| using | StagedVersions | The versions found in downloads/ for each of one project's download rows. There is one list per row, in the same order as DownloadUrls, and each list holds the versions that its row has a file for, newest first. A literal row's list is always empty. |
Functions
| bool | is_download_pattern(const std::string & url) |
| std::string | resolve_download_url(const std::string & url, const std::string & version) |
| bool | match_download_pattern(const std::string & pattern, const std::string & path, std::string & version) |
| StagedVersions | scan_staged_versions(const DownloadUrls & urls, const std::filesystem::path & downloads_root) |
| ServedSet | select_served_set(const DownloadUrls & urls, const StagedVersions & staged, const std::string & latest_tag, const std::vector<std::string> & published) |
| std::vector<std::string> | version_downloads(const DownloadUrls & urls, const StagedVersions & staged, const std::string & label, const std::string & built_tag) |
Type Alias Documentation
using DownloadUrls = std::vector<std::string>
The URLs of one project's download rows, in config order.
A download row is one entry in the project's downloads[] config. A row
whose URL has a {version} token is a pattern row. Any other row is a
literal row, which names one file.
using StagedVersions = std::vector<std::vector<std::string>>
The versions found in downloads/ for each of one project's download
rows. There is one list per row, in the same order as DownloadUrls, and
each list holds the versions that its row has a file for, newest first. A
literal row's list is always empty.
For the rows:
/downloads/app/app-{version}-linux.AppImage // Linux downloads for `app`
/downloads/app/app-{version}-setup.exe // Windows downloads for `app`
and a downloads/app/ folder containing these files:
app-3.0.0-linux.AppImage
app-3.0.1-linux.AppImage
app-3.0.0-setup.exe
it holds the following:
{
{ "3.0.1", "3.0.0" }, // Latest Linux version staged is `3.0.1`
{ "3.0.0" } // Windows `3.0.1` isn't staged yet
}
Function Documentation
bool is_download_pattern(const std::string & url)
Returns true when url contains a {version} token.
std::string resolve_download_url(const std::string & url, const std::string & version)
Replaces every {version} in url with version. A literal URL comes
back unchanged.
bool match_download_pattern(const std::string & pattern, const std::string & path, std::string & version)
Checks whether a file path fits a pattern, and if it does, fills version
with the path's version.
app-3.0.1-linux.AppImage fits app-{version}-linux.AppImage with
version 3.0.1. Returns false when the path doesn't fit, when the version
isn't a plain X.Y.Z (no v prefix, pre-release suffix, or leading
zeros), or when the path has different versions in two {version} spots.
A literal pattern never matches.
StagedVersions scan_staged_versions(const DownloadUrls & urls, const std::filesystem::path & downloads_root)
Looks in downloads_root (the site's downloads/ folder) for the files
named by one project's download rows.
Each pattern row only looks in the folder that its URL names, and only at
file names that fit its pattern, so other projects' files never count. A URL
outside /downloads/, or one with an empty, ., or .. folder name,
finds nothing. Every row finds nothing when downloads_root doesn't exist.
ServedSet select_served_set(const DownloadUrls & urls, const StagedVersions & staged, const std::string & latest_tag, const std::vector<std::string> & published)
Chooses which version the project's sidebar download buttons offer (the served version).
The served version is the newest X.Y.Z that meets all of these:
latest_tagpublished, a list of major.minor labels like 3.0When latest_tag is a major.minor label instead (a preview build's), any
patch of that minor counts as at or below it. Any other latest_tag
serves nothing.
Literal rows play no part in the choice, and their URLs come back unchanged. Each pattern row's URL becomes the served version's file, or "" when nothing is served.
candidate is the version that the site would ideally serve: latest_tag
itself, or for a preview, the newest version that has any file and meets
the first two rules. When the candidate isn't served, missing lists the
pattern rows that have no file for it.
std::vector<std::string> version_downloads(const DownloadUrls & urls, const StagedVersions & staged, const std::string & label, const std::string & built_tag)
Returns the download URL that each pattern row offers for one published version, for the versions page.
Only patches of label (a major.minor like 3.0) at or below built_tag
count, and an empty built_tag (a preview's) allows every patch. Each row
picks its own newest file, so rows may differ in patch: Linux could offer
3.0.1 while Windows still offers 3.0.0. A row with no file that
counts, and every literal row, gets "".