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