winbrew_core\fs/
mod.rs

1//! File-system helpers used by Winbrew's configuration, download, and install flows.
2//!
3//! This module provides atomic, transactional filesystem operations with
4//! Windows-specific security considerations such as reparse points and hard
5//! links.
6//!
7//! # Operations
8//!
9//! | Operation | Purpose | Atomicity |
10//! |-----------|---------|-----------|
11//! | [`cleanup_path`] | Remove files and directories with deferred-delete fallback | Best-effort |
12//! | [`replace_directory`] | Swap directories with rollback and cross-volume fallback | Transactional |
13//! | [`atomic_write`] | Write files atomically via temp file + rename | All-or-nothing |
14//! | [`extract_archive`] | Extract archives with path traversal protection | Rollback on fail |
15//!
16//! # Platform Behavior
17//!
18//! - **Windows**: Handles junction points, hard links, and cross-volume copies.
19//! - **Unix**: Standard POSIX semantics; reparse-point checks are no-ops.
20//!
21//! # Example
22//!
23//! ```no_run
24//! use std::path::Path;
25//! use winbrew_core::fs::{atomic_write, cleanup_path, replace_directory};
26//!
27//! atomic_write(
28//!     Path::new("config.toml"),
29//!     Path::new("config.toml.tmp"),
30//!     b"key = value",
31//! ).map_err(|err| *err)?;
32//!
33//! replace_directory(Path::new("staging/app"), Path::new("app")).map_err(|err| *err)?;
34//! cleanup_path(Path::new("app.old")).map_err(|err| *err)?;
35//! # Ok::<(), winbrew_core::fs::FsError>(())
36//! ```
37
38mod archive;
39mod cleanup;
40mod error;
41mod move_or_copy;
42mod write;
43
44pub use crate::paths::{
45    sevenz_bin_path_from_runtime_root, sevenz_dll_path_from_runtime_root,
46    sevenz_runtime_dir_from_runtime_root, system_sevenz_binary_path,
47};
48pub use archive::{ArchiveKind, extract_archive, extract_zip_archive};
49pub use cleanup::cleanup_path;
50pub use error::{FsError, Result};
51pub use move_or_copy::{backup_path_for, replace_directory};
52pub use write::{atomic_write, atomic_write_toml_temp, finalize_temp_file};