winbrew_core/lib.rs
1//! Core utilities shared by Winbrew.
2//!
3//! `winbrew-core` owns the reusable helpers that higher layers rely on for
4//! filesystem layout, path resolution, hashing, downloads, temp workspaces,
5//! cancellation, and time formatting. The crate keeps those boundaries in one
6//! place so the app, storage, engines, and CLI layers can share the same
7//! runtime contract.
8//!
9//! Public modules:
10//!
11//! - `env`: environment variable names used for root resolution
12//! - `paths`: managed-root and derived directory helpers
13//! - `temp_workspace`: repo-independent staging roots
14//! - `hash`: checksum helpers and digest validation
15//! - `network`: download client and installer filename helpers
16//! - `fs`: filesystem helpers used by install, update, and repair flows
17//! - `time`: timestamp helpers for persistence and reporting
18//! - `cancel`: Ctrl+C handling for long-running operations
19//!
20//! ## Environment Configuration
21//!
22//! The core crate exposes the Windows environment variable names that
23//! higher-level code uses while resolving paths.
24//!
25//! ```no_run
26//! use winbrew_core::env;
27//!
28//! if let Ok(custom_root) = std::env::var(env::WINBREW_PATHS_ROOT) {
29//! println!("Using custom root: {custom_root}");
30//! }
31//! ```
32//!
33//! When `WINBREW_PATHS_ROOT` is not set, the application root is typically
34//! derived from [`env::LOCALAPPDATA`] and expanded into the resolved path set
35//! in [`crate::paths::ResolvedPaths`].
36
37pub mod cancel;
38pub mod env;
39pub mod fs;
40pub mod hash;
41pub mod network;
42pub mod paths;
43pub mod temp_workspace;
44pub mod time;
45
46pub use cancel::{CancellationError, check, init_handler, is_cancelled};
47pub use env::{LOCALAPPDATA, WINBREW_PATHS_ROOT};
48pub use fs::{
49 ArchiveKind, FsError, Result as FsResult, atomic_write, atomic_write_toml_temp,
50 backup_path_for, cleanup_path, extract_archive, extract_zip_archive, finalize_temp_file,
51 replace_directory,
52};
53pub use hash::{
54 HashError, Hasher, Result as HashResult, hash_algorithm, normalize_hash, verify_hash,
55};
56pub use network::{
57 BoxError as NetworkBoxError, Client, DownloadError, Result as NetworkResult, build_client,
58 download_url_to_temp_file, installer_filename, is_zip_path,
59};
60pub use paths::{
61 ResolvedPaths, cache_dir_at, cache_file_at, catalog_db_at, config_file_at, data_dir_at,
62 db_dir_at, db_path_at, install_root_from_package_dir, log_dir_at, log_file_at,
63 package_journal_file_at, pkgdb_dir_at, resolve_template, resolved_paths,
64};
65pub use temp_workspace::{build_temp_root, temp_root_base, temp_root_prefix};
66pub use time::{now, now_ms};