app: check Gitea releases and install update capsules
record-daemon / Check and lint (Linux) (push) Successful in 1m5s
record-daemon / Build (Windows x64) (push) Successful in 1m54s

The app asks the project's Gitea release list about five seconds after
startup and every six hours. A stable release beats a newer prerelease,
and a release is offered only when its tag is newer than the running
build and it carries a .capsule asset for this target.

A capsule is a ZIP with capsule.json and a payload. Every payload file
carries its size and BLAKE3 digest in the manifest, and staging rejects
absolute paths, parent segments, undeclared entries, digest mismatches,
and versions that are not newer. The verified payload is stored under the
app data directory, so a download survives a restart.

The manifest and archive format live in crates/capsule-format, shared by
the app's verifier and the release tool.

Settings > Advanced shows the state, the notes, and the download and
install buttons. The status bar shows an accent chip while an update is
waiting. Install copies the app to a temp helper, asks the daemon to stop,
and quits. The helper waits for the process, swaps the files with a
rollback copy of each old file, removes stale files, and starts the new
app. A failed swap puts the old files back and logs the reason.

--check-updates runs the release check from a shell. The release tool in
tools/capsule builds a capsule from the same files the installer puts
down, using packager.toml, so a release does not need an installed copy.
docs/updates.md covers the format and the release steps.
This commit is contained in:
vhaudiquet committed 2026-11-24 21:59:17 +01:00
1 parent 9d1fb40434
commit e3a62aa6ae
17 files changed
+3535 -6

No files matched your search

+419
View File
@@ -0,0 +1,419 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "arrayvec"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
[[package]]
name = "bitflags"
version = "2.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
[[package]]
name = "blake3"
version = "1.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae"
dependencies = [
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq 0.4.2",
"cpufeatures",
]
[[package]]
name = "bumpalo"
version = "3.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
[[package]]
name = "capsule-format"
version = "0.1.0"
dependencies = [
"blake3",
"semver",
"serde",
"serde_json",
"zip",
]
[[package]]
name = "cc"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "cfg_aliases"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
[[package]]
name = "constant_time_eq"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"
[[package]]
name = "constant_time_eq"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9"
dependencies = [
"rustversion",
]
[[package]]
name = "cpufeatures"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
dependencies = [
"cfg-if",
]
[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
[[package]]
name = "flate2"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
dependencies = [
"zlib-rs",
]
[[package]]
name = "getrandom"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"r-efi",
"wasm-bindgen",
]
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
[[package]]
name = "js-sys"
version = "0.3.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "nix"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
[[package]]
name = "semver"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "serde_json"
version = "1.0.154"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
dependencies = [
"itoa",
"memchr",
"serde",
"serde_core",
"zmij",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typed-path"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e"
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[[package]]
name = "wasm-bindgen"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
dependencies = [
"cfg-if",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn 3.0.10",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "zeroize"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "zip"
version = "9.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80cc68510ea7553c30a69c732de5278e94183f68765af6c642dbccefd6ec777e"
dependencies = [
"constant_time_eq 0.6.1",
"crc32fast",
"flate2",
"getrandom",
"indexmap",
"libc",
"memchr",
"nix",
"typed-path",
"windows-sys",
"zeroize",
]
[[package]]
name = "zlib-rs"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
[[package]]
name = "zmij"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "capsule-format"
version = "0.1.0"
edition = "2024"
description = "The .capsule manifest and archive format shared by the app and the release tool"
license = "MIT"
[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
semver = "1"
blake3 = "1"
zip = { version = "9.6", default-features = false, features = ["deflate-flate2-zlib-rs"] }
+365
View File
@@ -0,0 +1,365 @@
//! The `.capsule` archive the updater reads and the release tool writes.
//!
//! A capsule is a ZIP with `capsule.json` at the root and every installed file under
//! `payload/`. The manifest names each file with its size and BLAKE3 digest.
use semver::Version;
use std::collections::HashSet;
use std::fs::{self, File};
use std::io::{BufWriter, Read, Write};
use std::path::{Path, PathBuf};
/// The product name a capsule must carry.
pub const PRODUCT: &str = "leaguerecorder";
/// The capsule manifest version this build understands.
pub const CAPSULE_FORMAT: u32 = 1;
/// The target string a capsule is built for, such as `windows-x86_64`.
pub fn target() -> &'static str {
if cfg!(all(target_os = "windows", target_arch = "x86_64")) {
"windows-x86_64"
} else if cfg!(all(target_os = "windows", target_arch = "aarch64")) {
"windows-aarch64"
} else if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
"linux-x86_64"
} else if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
"macos-aarch64"
} else if cfg!(all(target_os = "macos", target_arch = "x86_64")) {
"macos-x86_64"
} else {
"unknown"
}
}
/// The app binary's name, which is also the capsule entry.
pub fn default_entry() -> &'static str {
if cfg!(windows) {
"leaguerecorder.exe"
} else {
"leaguerecorder"
}
}
/// One file in a capsule: its path relative to the install root, its size, and its BLAKE3
/// digest in lowercase hex.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct FileEntry {
pub path: String,
pub size: u64,
pub blake3: String,
}
/// `capsule.json`: what a capsule holds and the version it installs.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Manifest {
pub format: u32,
pub product: String,
pub version: String,
pub target: String,
pub entry: String,
#[serde(default)]
pub notes: String,
pub files: Vec<FileEntry>,
/// Files from an older install that the new version no longer ships.
#[serde(default)]
pub remove: Vec<String>,
}
/// The byte for a backslash. Capsule paths use forward slashes only.
const BACKSLASH: u8 = 0x5c;
/// A relative path a capsule may name. Anything that could leave the install root is refused:
/// an absolute path, a drive prefix, a backslash, an empty segment, `.` or `..`.
pub fn safe_relative(path: &str) -> bool {
if path.is_empty()
|| path.starts_with('/')
|| path.as_bytes().contains(&BACKSLASH)
|| path.contains(':')
{
return false;
}
!path
.split('/')
.any(|part| part.is_empty() || part == "." || part == "..")
}
fn hash_file(path: &Path) -> Result<(u64, String), String> {
let mut file = File::open(path).map_err(|e| format!("cannot read {}: {e}", path.display()))?;
let mut hasher = blake3::Hasher::new();
let mut size = 0u64;
let mut buf = [0u8; 64 * 1024];
loop {
let read = file
.read(&mut buf)
.map_err(|e| format!("cannot read {}: {e}", path.display()))?;
if read == 0 {
break;
}
size += read as u64;
hasher.update(&buf[..read]);
}
Ok((size, hasher.finalize().to_hex().to_string()))
}
impl Manifest {
/// Check the parts that do not depend on the running version.
pub fn validate(&self) -> Result<(), String> {
if self.format != CAPSULE_FORMAT {
return Err(format!(
"the capsule has format {}, and this app reads {CAPSULE_FORMAT}",
self.format
));
}
if self.product != PRODUCT {
return Err(format!(
"the capsule is for {}, not {PRODUCT}",
self.product
));
}
if self.target != target() {
return Err(format!(
"the capsule is built for {}, and this app runs on {}",
self.target,
target()
));
}
if self.files.is_empty() {
return Err("the capsule holds no files".into());
}
if !safe_relative(&self.entry) {
return Err(format!(
"the capsule entry {:?} is not a plain path",
self.entry
));
}
let mut seen = HashSet::new();
for file in &self.files {
if !safe_relative(&file.path) {
return Err(format!(
"the capsule names {:?}, which is not a plain path under the install folder",
file.path
));
}
if !seen.insert(file.path.as_str()) {
return Err(format!("the capsule names {} twice", file.path));
}
if file.blake3.len() != 64 || !file.blake3.chars().all(|c| c.is_ascii_hexdigit()) {
return Err(format!("{} has no BLAKE3 digest", file.path));
}
}
if !seen.contains(self.entry.as_str()) {
return Err(format!(
"the capsule entry {} is not one of its files",
self.entry
));
}
for path in &self.remove {
if !safe_relative(path) {
return Err(format!(
"the capsule asks to remove {path:?}, which is not a plain path under the install folder"
));
}
if seen.contains(path.as_str()) {
return Err(format!("the capsule installs and removes {path}"));
}
}
Ok(())
}
/// The version the capsule installs.
pub fn version(&self) -> Result<Version, String> {
Version::parse(&self.version)
.map_err(|e| format!("the capsule version {:?} does not parse: {e}", self.version))
}
}
/// Pack the install folder `dir` into `out` for `version`.
pub fn pack(dir: &Path, out: &Path, version: &str) -> Result<Manifest, String> {
let version = Version::parse(version)
.map_err(|e| format!("the version {version:?} does not parse: {e}"))?;
if !dir.join(default_entry()).is_file() {
return Err(format!("{} has no {}", dir.display(), default_entry()));
}
let mut paths = Vec::new();
collect_files(dir, out, &mut paths)?;
paths.sort();
let mut files = Vec::new();
for path in &paths {
let relative = path
.strip_prefix(dir)
.map_err(|_| format!("{} is not under {}", path.display(), dir.display()))?;
let relative = relative
.components()
.filter_map(|part| match part {
std::path::Component::Normal(part) => Some(part.to_string_lossy().to_string()),
_ => None,
})
.collect::<Vec<_>>()
.join("/");
let (size, blake3) = hash_file(path)?;
files.push(FileEntry {
path: relative,
size,
blake3,
});
}
if files.is_empty() {
return Err(format!("{} holds no files", dir.display()));
}
let manifest = Manifest {
format: CAPSULE_FORMAT,
product: PRODUCT.into(),
version: version.to_string(),
target: target().into(),
entry: default_entry().into(),
notes: String::new(),
files,
remove: Vec::new(),
};
manifest.validate()?;
if let Some(parent) = out.parent() {
fs::create_dir_all(parent)
.map_err(|e| format!("cannot create {}: {e}", parent.display()))?;
}
let part = out.with_extension("capsule.part");
let file = File::create(&part).map_err(|e| format!("cannot write {}: {e}", part.display()))?;
let mut zip = zip::ZipWriter::new(BufWriter::new(file));
let options = zip::write::SimpleFileOptions::default()
.compression_method(zip::CompressionMethod::Deflated);
zip.start_file("capsule.json", options)
.map_err(|e| format!("cannot write capsule.json: {e}"))?;
let text = serde_json::to_vec_pretty(&manifest)
.map_err(|e| format!("the manifest did not serialize: {e}"))?;
zip.write_all(&text)
.map_err(|e| format!("cannot write capsule.json: {e}"))?;
for file in &manifest.files {
let path = dir.join(&file.path);
zip.start_file(format!("payload/{}", file.path), options)
.map_err(|e| format!("cannot add {}: {e}", file.path))?;
let mut input =
File::open(&path).map_err(|e| format!("cannot read {}: {e}", path.display()))?;
std::io::copy(&mut input, &mut zip)
.map_err(|e| format!("cannot add {}: {e}", file.path))?;
}
let mut writer = zip
.finish()
.map_err(|e| format!("cannot finish the capsule: {e}"))?;
writer
.flush()
.map_err(|e| format!("cannot finish {}: {e}", part.display()))?;
drop(writer);
fs::rename(&part, out).map_err(|e| format!("cannot write {}: {e}", out.display()))?;
Ok(manifest)
}
fn collect_files(dir: &Path, out: &Path, files: &mut Vec<PathBuf>) -> Result<(), String> {
let entries = fs::read_dir(dir).map_err(|e| format!("cannot read {}: {e}", dir.display()))?;
for entry in entries.flatten() {
let path = entry.path();
if path == out || path == out.with_extension("capsule.part") {
continue;
}
let kind = entry
.file_type()
.map_err(|e| format!("cannot read {}: {e}", path.display()))?;
if kind.is_dir() {
collect_files(&path, out, files)?;
} else if kind.is_file() {
let name = path
.file_name()
.map(|name| name.to_string_lossy().to_ascii_lowercase())
.unwrap_or_default();
if name.ends_with(".capsule") || name.ends_with(".lrnew") || name.ends_with(".lrold") {
continue;
}
files.push(path);
}
}
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
fn digest(bytes: &[u8]) -> String {
blake3::hash(bytes).to_hex().to_string()
}
fn manifest(version: &str, files: &[(&str, &[u8])]) -> Manifest {
Manifest {
format: CAPSULE_FORMAT,
product: PRODUCT.into(),
version: version.into(),
target: target().into(),
entry: default_entry().into(),
notes: String::new(),
files: files
.iter()
.map(|(path, bytes)| FileEntry {
path: (*path).into(),
size: bytes.len() as u64,
blake3: digest(bytes),
})
.collect(),
remove: Vec::new(),
}
}
#[test]
fn capsule_paths_must_stay_under_the_install_folder() {
for bad in [
"../evil.exe",
"/etc/passwd",
"a/../../b",
"C:/Windows/system32",
"a//b",
"./a",
"",
] {
let mut manifest = manifest("0.4.0", &[(default_entry(), b"app")]);
manifest.files[0].path = bad.into();
assert!(manifest.validate().is_err(), "{bad:?} was accepted");
}
assert!(!safe_relative(&format!("a{}b", char::from(0x5cu8))));
}
#[test]
fn the_entry_must_be_one_of_the_files() {
let mut manifest = manifest("0.4.0", &[(default_entry(), b"app")]);
manifest.entry = "other.exe".into();
assert!(manifest.validate().is_err());
}
#[test]
fn a_capsule_with_the_wrong_target_is_refused() {
let mut manifest = manifest("0.4.0", &[(default_entry(), b"app")]);
manifest.target = "plan9-sparc".into();
assert!(manifest.validate().is_err());
}
#[test]
fn a_folder_packs_with_a_manifest_that_names_every_file() {
let root = std::env::temp_dir().join(format!("capsule-format-pack-{}", std::process::id()));
let payload = root.join("payload");
fs::create_dir_all(payload.join("data")).unwrap();
fs::write(payload.join(default_entry()), b"app").unwrap();
fs::write(payload.join("data").join("file.bin"), b"some data").unwrap();
let manifest = pack(&payload, &root.join("release.capsule"), "0.4.0").unwrap();
assert_eq!(manifest.files.len(), 2);
assert_eq!(manifest.version, "0.4.0");
assert!(manifest.validate().is_ok());
let file = File::open(root.join("release.capsule")).unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();
assert!(archive.by_name("capsule.json").is_ok());
assert!(archive.by_name("payload/data/file.bin").is_ok());
drop(archive);
let _ = fs::remove_dir_all(&root);
}
}