[control] Pause fixes: Restore waits until an unsaved pause is on disk, unwritable config files pause with a way out, a failed promote at start starts paused, a revert that cannot see edge is not reverted
This commit is contained in:
@@ -55,6 +55,7 @@ pub fn ct_eq(a: &[u8], b: &[u8]) -> bool {
|
||||
/// the new content survives a crash once this returns: temporary file in the same directory,
|
||||
/// fsync, rename, fsync of the directory.
|
||||
pub fn write_atomic(path: &Path, data: &[u8], mode: u32) -> std::io::Result<()> {
|
||||
crate::crash::fail_write(path).map_err(std::io::Error::other)?;
|
||||
let dir = path
|
||||
.parent()
|
||||
.filter(|p| !p.as_os_str().is_empty())
|
||||
@@ -80,6 +81,7 @@ pub fn write_atomic(path: &Path, data: &[u8], mode: u32) -> std::io::Result<()>
|
||||
|
||||
/// Rename `from` to `to` atomically and durably.
|
||||
pub fn rename_durable(from: &Path, to: &Path) -> std::io::Result<()> {
|
||||
crate::crash::fail_write(to).map_err(std::io::Error::other)?;
|
||||
std::fs::rename(from, to)?;
|
||||
sync_dir(to.parent().unwrap_or(Path::new(".")))
|
||||
}
|
||||
@@ -114,7 +116,6 @@ pub fn read_json<T: DeserializeOwned>(path: &Path) -> Result<Option<T>, String>
|
||||
|
||||
/// Write a JSON state file atomically, readable by its owner only.
|
||||
pub fn write_json<T: Serialize>(path: &Path, value: &T) -> Result<(), String> {
|
||||
crate::crash::fail_write(path)?;
|
||||
let mut text = serde_json::to_vec_pretty(value).map_err(|e| e.to_string())?;
|
||||
text.push(b'\n');
|
||||
write_atomic(path, &text, 0o600).map_err(|e| format!("cannot write {}: {e}", path.display()))
|
||||
|
||||
Reference in New Issue
Block a user