Set mode 0o600 on updater state file

This commit is contained in:
Malte Meiboom
2026-08-13 11:54:29 +02:00
parent add79d1796
commit e8f4b16314
+12 -6
View File
@@ -6,6 +6,9 @@ use std::fs::OpenOptions;
use std::io::{Read, Write};
use std::path::Path;
#[cfg(unix)]
use std::os::unix::fs::OpenOptionsExt;
use chrono::{Local, NaiveDateTime};
use rand::prelude::*;
use sequoia_openpgp::Fingerprint;
@@ -105,6 +108,7 @@ impl CertState {
}
}
/// Check if this certificate is already processed.
pub fn need_processing(&self) -> bool {
!(self.processed || (self.retry_count >= MAX_RETRY))
}
@@ -217,7 +221,7 @@ impl UpdaterState {
}
/// Increment the retry count of the certificate (identified by its
/// fingerprint.
/// fingerprint).
pub fn incr_retry_count(&mut self, fpr: &Fingerprint) {
if let Some(entry) = self.certs.get_mut(fpr) {
entry.incr_retry_count();
@@ -292,12 +296,14 @@ impl UpdaterState {
pub async fn freeze(file: &Path, updater_state: &UpdaterState) -> Result<(), UpdaterError> {
// freeze comes after thaw, so we assume that the parent directory
// exists.
// XXX: on unix set mode 0o666
let mut handle = OpenOptions::new()
.write(true)
let mut options = OpenOptions::new();
options.write(true)
.create(true)
.truncate(true)
.open(file)
.truncate(true);
#[cfg(unix)]
options.mode(0o600);
let mut handle = options.open(file)
.map_err(|e| UpdaterError::IoError(e.to_string()))?;
handle.write_all(updater_state.to_string().as_bytes())