Compare commits

..
Author SHA1 Message Date
nvrl 233d9e9e51 refactor(core): atomic file writes from proton-base-rs
Config, machine id and mount-failure files go through
proton_base_rs::atomic. Same modes as before (config 0600, the others
0644); the mount-failure file is now synced before its rename.
2026-11-20 12:16:32 +01:00
6 changed files with 27 additions and 39 deletions

No files matched your search

Generated
+18 -7
View File
@@ -1476,7 +1476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -1931,7 +1931,7 @@ dependencies = [
"gobject-sys", "gobject-sys",
"libc", "libc",
"system-deps 9.0.1", "system-deps 9.0.1",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -3633,6 +3633,7 @@ dependencies = [
"libc", "libc",
"parking_lot 0.13.0", "parking_lot 0.13.0",
"proton-auth-rs", "proton-auth-rs",
"proton-base-rs",
"proton-drive-rs", "proton-drive-rs",
"proton-gallery-rs", "proton-gallery-rs",
"proton-sdk", "proton-sdk",
@@ -3938,6 +3939,16 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "proton-base-rs"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "451151bb1025ea5cb362f69e2bfb2d45afed603e5c6daa3dc752333a7c29c878"
dependencies = [
"rusqlite",
"thiserror 2.0.21",
]
[[package]] [[package]]
name = "proton-drive-rs" name = "proton-drive-rs"
version = "0.12.1" version = "0.12.1"
@@ -4155,7 +4166,7 @@ dependencies = [
"once_cell", "once_cell",
"socket2", "socket2",
"tracing", "tracing",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -4610,7 +4621,7 @@ dependencies = [
"errno", "errno",
"libc", "libc",
"linux-raw-sys", "linux-raw-sys",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -4667,7 +4678,7 @@ dependencies = [
"security-framework", "security-framework",
"security-framework-sys", "security-framework-sys",
"webpki-root-certs", "webpki-root-certs",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -5175,7 +5186,7 @@ dependencies = [
"getrandom 0.4.3", "getrandom 0.4.3",
"once_cell", "once_cell",
"rustix", "rustix",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -5840,7 +5851,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
+1
View File
@@ -66,6 +66,7 @@ keyring-core = "1"
# The keyring store all three apps share: reconnects after a Secret Service # The keyring store all three apps share: reconnects after a Secret Service
# restart (B285) and replaces items instead of editing them (B291). # restart (B285) and replaces items instead of editing them (B291).
proton-auth-rs = "0.1" proton-auth-rs = "0.1"
proton-base-rs = "0.1"
dbus-secret-service-keyring-store = { version = "1", features = ["crypto-rust"] } dbus-secret-service-keyring-store = { version = "1", features = ["crypto-rust"] }
# The same Secret Service client the store wraps, used directly to replace an # The same Secret Service client the store wraps, used directly to replace an
# item instead of editing it, which oo7 before 0.7.0 kept only in memory (B291). # item instead of editing it, which oo7 before 0.7.0 kept only in memory (B291).
+1
View File
@@ -26,6 +26,7 @@ sha2.workspace = true
rusqlite.workspace = true rusqlite.workspace = true
keyring-core.workspace = true keyring-core.workspace = true
proton-auth-rs = { workspace = true, features = ["keyring"] } proton-auth-rs = { workspace = true, features = ["keyring"] }
proton-base-rs.workspace = true
dbus-secret-service-keyring-store.workspace = true dbus-secret-service-keyring-store.workspace = true
dbus-secret-service.workspace = true dbus-secret-service.workspace = true
parking_lot.workspace = true parking_lot.workspace = true
+3 -29
View File
@@ -457,26 +457,7 @@ fn load_config_at(path: &Path) -> AppConfig {
/// [`AppDirs::save_config`] for the file at `path`. /// [`AppDirs::save_config`] for the file at `path`.
fn save_config_at(path: &Path, config: &AppConfig) -> Result<()> { fn save_config_at(path: &Path, config: &AppConfig) -> Result<()> {
refuse_to_replace_unreadable(path)?; refuse_to_replace_unreadable(path)?;
let parent = path proton_base_rs::atomic::write(path, &serde_json::to_vec_pretty(config)?)?;
.parent()
.ok_or_else(|| Error::Other("configuration path has no parent".into()))?;
std::fs::create_dir_all(parent)?;
let nonce = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|duration| duration.as_nanos())
.unwrap_or(0);
let tmp = path.with_extension(format!("json.tmp-{}-{nonce}", std::process::id()));
use std::os::unix::fs::OpenOptionsExt as _;
let mut file = std::fs::OpenOptions::new()
.write(true)
.create_new(true)
.mode(0o600)
.open(&tmp)?;
use std::io::Write as _;
file.write_all(&serde_json::to_vec_pretty(config)?)?;
file.sync_all()?;
std::fs::rename(&tmp, path)?;
std::fs::File::open(parent)?.sync_all()?;
Ok(()) Ok(())
} }
@@ -621,15 +602,8 @@ impl AppDirs {
use std::io::Read as _; use std::io::Read as _;
std::fs::File::open("/dev/urandom")?.read_exact(&mut bytes)?; std::fs::File::open("/dev/urandom")?.read_exact(&mut bytes)?;
let id: String = bytes.iter().map(|b| format!("{b:02x}")).collect(); let id: String = bytes.iter().map(|b| format!("{b:02x}")).collect();
let parent = path // Not secret, and other tools may read it; keep it world-readable.
.parent() proton_base_rs::atomic::write_with_mode(&path, format!("{id}\n").as_bytes(), 0o644)?;
.ok_or_else(|| Error::Other("machine id path has no parent".into()))?;
std::fs::create_dir_all(parent)?;
let tmp = path.with_extension(format!("tmp-{}", std::process::id()));
std::fs::write(&tmp, format!("{id}\n"))?;
std::fs::File::open(&tmp)?.sync_all()?;
std::fs::rename(&tmp, &path)?;
std::fs::File::open(parent)?.sync_all()?;
Ok(id) Ok(id)
} }
+1 -3
View File
@@ -40,9 +40,7 @@ pub fn path(state_dir: &Path) -> PathBuf {
/// and renamed, so a reader never sees half of it. /// and renamed, so a reader never sees half of it.
pub fn record(state_dir: &Path, failure: &MountFailure) -> std::io::Result<()> { pub fn record(state_dir: &Path, failure: &MountFailure) -> std::io::Result<()> {
let json = serde_json::to_vec(failure).map_err(std::io::Error::other)?; let json = serde_json::to_vec(failure).map_err(std::io::Error::other)?;
let tmp = state_dir.join(format!("{FILE_NAME}.tmp")); proton_base_rs::atomic::write_with_mode(&path(state_dir), &json, 0o644)
std::fs::write(&tmp, json)?;
std::fs::rename(&tmp, path(state_dir))
} }
/// Forget the failure: a mount is up, or a new daemon has started. /// Forget the failure: a mount is up, or a new daemon has started.
+3
View File
@@ -22,6 +22,9 @@ scratch (user data in `staging/` and `recovery/` is never touched by this).
- The keyring code (one Secret Service connection that reconnects after the provider - The keyring code (one Secret Service connection that reconnects after the provider
restarts, B285, and replacing the session item instead of editing it, B291) now comes restarts, B285, and replacing the session item instead of editing it, B291) now comes
from `proton-auth-rs`, shared with Proton Gallery and Proton Stream. No behaviour change. from `proton-auth-rs`, shared with Proton Gallery and Proton Stream. No behaviour change.
- Config, machine-id and mount-failure files are written through `proton-base-rs`'s
atomic writer (temporary file, sync, rename, directory sync). The mount-failure file
is now synced before the rename too, so a crash cannot leave it empty.
## [3.9.0] — 2026-11-19 ## [3.9.0] — 2026-11-19