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

+489
View File
@@ -0,0 +1,489 @@
# 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 = "glob"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
[[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 = "make-capsule"
version = "0.1.0"
dependencies = [
"capsule-format",
"glob",
"serde",
"toml",
]
[[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 = "serde_spanned"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782"
dependencies = [
"serde_core",
]
[[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 = "toml"
version = "1.2.2+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5426cb1b964690d913f6c5c1a1ae0b42f428ec506bb4d452876d7a209c9bca3b"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "1.1.3+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49"
dependencies = [
"serde_core",
]
[[package]]
name = "toml_parser"
version = "1.1.6+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6769c452d71ba30696c6b37770c439a9cc9110f47f7d5cdbeda79840ef5ea31"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.2.0+spec-1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a"
[[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 = "winnow"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef"
[[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"
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "make-capsule"
version = "0.1.0"
edition = "2024"
description = "Build a .capsule update archive from the release build"
license = "MIT"
[dependencies]
capsule-format = { path = "../../crates/capsule-format" }
serde = { version = "1", features = ["derive"] }
toml = "1"
glob = "0.3"
+336
View File
@@ -0,0 +1,336 @@
//! Build a `.capsule` update archive from the release build.
//!
//! The install tree comes from `packager.toml`, so the capsule carries exactly the files the
//! installer puts down. No installed copy of the app is needed.
use serde::Deserialize;
use std::fs;
use std::path::{Path, PathBuf};
#[derive(Debug, Deserialize)]
struct Config {
version: String,
#[serde(rename = "binaries-dir", default)]
binaries_dir: Option<String>,
#[serde(default)]
binaries: Vec<Binary>,
#[serde(default)]
resources: Vec<Resource>,
#[serde(rename = "out-dir", default)]
out_dir: Option<String>,
}
#[derive(Debug, Deserialize)]
struct Binary {
path: String,
}
#[derive(Debug, Deserialize)]
struct Resource {
src: String,
#[serde(default)]
target: String,
}
fn main() {
if let Err(e) = run(std::env::args().skip(1).collect()) {
eprintln!("{e}");
std::process::exit(1);
}
}
fn run(args: Vec<String>) -> Result<(), String> {
let mut config = None;
let mut folder = None;
let mut out = None;
let mut version = None;
let mut args = args.into_iter();
while let Some(arg) = args.next() {
match arg.as_str() {
"--config" => config = Some(args.next().ok_or("--config needs a path")?),
"--folder" => folder = Some(args.next().ok_or("--folder needs a path")?),
"--out" => out = Some(args.next().ok_or("--out needs a path")?),
"--version" => version = Some(args.next().ok_or("--version needs a version")?),
"-h" | "--help" => {
println!("{}", usage());
return Ok(());
}
other => return Err(format!("unknown argument {other:?}\n\n{}", usage())),
}
}
match (config, folder) {
(Some(_), Some(_)) => Err("use --config or --folder, not both".into()),
(None, None) => Err(usage().into()),
(Some(config), None) => from_config(Path::new(&config), version, out),
(None, Some(folder)) => {
let version = version.ok_or("--version is required with --folder")?;
let out = out.ok_or("--out is required with --folder")?;
let manifest = capsule_format::pack(Path::new(&folder), Path::new(&out), &version)?;
println!(
"{}: {} files for {} on {}",
out,
manifest.files.len(),
manifest.version,
manifest.target
);
Ok(())
}
}
}
fn from_config(
config_path: &Path,
version: Option<String>,
out: Option<String>,
) -> Result<(), String> {
let text = fs::read_to_string(config_path)
.map_err(|e| format!("cannot read {}: {e}", config_path.display()))?;
let config: Config =
toml::from_str(&text).map_err(|e| format!("cannot read {}: {e}", config_path.display()))?;
if let Some(version) = version
&& version != config.version
{
return Err(format!(
"--version says {version}, and {} says {}; bump the file or drop the flag",
config_path.display(),
config.version
));
}
let config_dir = config_path.parent().unwrap_or(Path::new("."));
if let Some(cargo) = cargo_version(config_dir)
&& cargo != config.version
{
return Err(format!(
"{} says {cargo}, and {} says {}; bump both",
config_dir.join("Cargo.toml").display(),
config_path.display(),
config.version
));
}
let out = out.map(PathBuf::from).unwrap_or_else(|| {
config_dir
.join(config.out_dir.as_deref().unwrap_or("dist"))
.join(format!(
"{}-{}-{}.capsule",
capsule_format::PRODUCT,
config.version,
capsule_format::target()
))
});
let stage = std::env::temp_dir().join(format!("make-capsule-{}", std::process::id()));
if stage.exists() {
fs::remove_dir_all(&stage).map_err(|e| format!("cannot clear {}: {e}", stage.display()))?;
}
fs::create_dir_all(&stage).map_err(|e| format!("cannot create {}: {e}", stage.display()))?;
let result = (|| {
stage_config(&config, config_dir, &stage)?;
let manifest = capsule_format::pack(&stage, &out, &config.version)?;
println!(
"{}: {} files for {} on {}",
out.display(),
manifest.files.len(),
manifest.version,
manifest.target
);
Ok(())
})();
let _ = fs::remove_dir_all(&stage);
result
}
fn cargo_version(dir: &Path) -> Option<String> {
let text = fs::read_to_string(dir.join("Cargo.toml")).ok()?;
let value: toml::Value = toml::from_str(&text).ok()?;
value
.get("package")?
.get("version")?
.as_str()
.map(str::to_string)
}
fn usage() -> &'static str {
"usage:\n \
make-capsule --config <packager.toml> [--out <file>]\n \
make-capsule --folder <install-root> --version <x.y.z> --out <file>"
}
fn stage_config(config: &Config, dir: &Path, stage: &Path) -> Result<(), String> {
let binaries_dir = dir.join(config.binaries_dir.as_deref().unwrap_or("."));
for binary in &config.binaries {
let source = with_exe(binaries_dir.join(&binary.path));
copy_file(&source, &stage.join(file_name(&source)?))?;
}
for resource in &config.resources {
copy_resource(dir, resource, stage)?;
}
Ok(())
}
fn with_exe(path: PathBuf) -> PathBuf {
if cfg!(windows) && path.extension().is_none() {
path.with_extension("exe")
} else {
path
}
}
fn copy_resource(dir: &Path, resource: &Resource, stage: &Path) -> Result<(), String> {
let source = dir.join(&resource.src);
let pattern = source.to_string_lossy().replace(char::from(0x5c), "/");
if pattern.contains(['*', '?', '[']) {
let mut found = false;
for path in
glob::glob(&pattern).map_err(|e| format!("{} is not a glob: {e}", source.display()))?
{
let path = path.map_err(|e| format!("cannot read {}: {e}", source.display()))?;
if path.is_file() {
found = true;
let target = target_dir(stage, &resource.target)?;
copy_file(&path, &target.join(file_name(&path)?))?;
}
}
if !found {
return Err(format!("{} matched no files", source.display()));
}
return Ok(());
}
if source.is_dir() {
copy_dir(&source, &target_dir(stage, &resource.target)?)
} else if source.is_file() {
let target = if resource.target.is_empty()
|| resource.target == "."
|| resource.target.ends_with('/')
|| resource.target.ends_with(char::from(0x5c))
{
target_dir(stage, &resource.target)?.join(file_name(&source)?)
} else {
stage.join(&resource.target)
};
copy_file(&source, &target)
} else {
Err(format!("{} does not exist", source.display()))
}
}
fn target_dir(stage: &Path, target: &str) -> Result<PathBuf, String> {
if target.is_empty() || target == "." {
return Ok(stage.to_path_buf());
}
if target.starts_with('/')
|| target.starts_with(char::from(0x5c))
|| target.contains(':')
|| target
.split(['/', char::from(0x5c)])
.any(|part| part == "..")
{
return Err(format!("resource target {target:?} is not a relative path"));
}
Ok(stage.join(target))
}
fn copy_dir(from: &Path, to: &Path) -> Result<(), String> {
fs::create_dir_all(to).map_err(|e| format!("cannot create {}: {e}", to.display()))?;
let entries = fs::read_dir(from).map_err(|e| format!("cannot read {}: {e}", from.display()))?;
for entry in entries {
let entry = entry.map_err(|e| format!("cannot read {}: {e}", from.display()))?;
let path = entry.path();
let dest = to.join(entry.file_name());
if path.is_dir() {
copy_dir(&path, &dest)?;
} else if path.is_file() {
copy_file(&path, &dest)?;
}
}
Ok(())
}
fn copy_file(from: &Path, to: &Path) -> Result<(), String> {
if let Some(parent) = to.parent() {
fs::create_dir_all(parent)
.map_err(|e| format!("cannot create {}: {e}", parent.display()))?;
}
fs::copy(from, to)
.map(|_| ())
.map_err(|e| format!("cannot copy {} to {}: {e}", from.display(), to.display()))
}
fn file_name(path: &Path) -> Result<std::ffi::OsString, String> {
path.file_name()
.map(|name| name.to_os_string())
.ok_or_else(|| format!("{} has no file name", path.display()))
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
fn temp_dir(tag: &str) -> PathBuf {
let dir =
std::env::temp_dir().join(format!("make-capsule-test-{tag}-{}", std::process::id()));
let _ = fs::remove_dir_all(&dir);
fs::create_dir_all(&dir).unwrap();
dir
}
#[test]
fn the_release_tree_follows_the_packager_entries() {
let root = temp_dir("stage");
let app = root.join("app");
fs::create_dir_all(app.join("target/release")).unwrap();
fs::write(app.join("target/release/leaguerecorder.exe"), b"app").unwrap();
fs::create_dir_all(app.join("vendor/vcruntime")).unwrap();
fs::write(app.join("vendor/vcruntime/vcruntime140.dll"), b"runtime").unwrap();
let daemon = root.join("daemon/target/release");
fs::create_dir_all(daemon.join("data")).unwrap();
fs::create_dir_all(daemon.join("obs-plugins")).unwrap();
fs::write(daemon.join("record-daemon.exe"), b"daemon").unwrap();
fs::write(daemon.join("libobs.dll"), b"dll").unwrap();
fs::write(daemon.join("data/area.effect"), b"effect").unwrap();
fs::write(daemon.join("obs-plugins/plugin.dll"), b"plugin").unwrap();
let config = Config {
version: "0.4.0".into(),
binaries_dir: Some("app/target/release".into()),
binaries: vec![Binary {
path: "leaguerecorder".into(),
}],
resources: vec![
Resource {
src: "daemon/target/release/record-daemon.exe".into(),
target: ".".into(),
},
Resource {
src: "daemon/target/release/*.dll".into(),
target: ".".into(),
},
Resource {
src: "daemon/target/release/data".into(),
target: "data".into(),
},
Resource {
src: "daemon/target/release/obs-plugins".into(),
target: "obs-plugins".into(),
},
Resource {
src: "app/vendor/vcruntime/*.dll".into(),
target: ".".into(),
},
],
out_dir: None,
};
let stage = root.join("stage-out");
stage_config(&config, &root, &stage).unwrap();
assert!(stage.join("leaguerecorder.exe").is_file());
assert!(stage.join("record-daemon.exe").is_file());
assert!(stage.join("libobs.dll").is_file());
assert!(stage.join("vcruntime140.dll").is_file());
assert!(stage.join("data/area.effect").is_file());
assert!(stage.join("obs-plugins/plugin.dll").is_file());
let _ = fs::remove_dir_all(&root);
}
}