Avoid APFS race condition
@@ -458,7 +458,7 @@ pub(crate) fn write_snapshot(
let mut path_2 = config.snapshot_prefix();
path_2.push(path_2_suffix);
- let _res = std::fs::create_dir_all(path_1.parent().unwrap());
+ std::fs::create_dir_all(path_1.parent().unwrap())?;
let mut f = std::fs::OpenOptions::new()
.write(true)
.create(true)
@@ -474,6 +474,11 @@ pub(crate) fn write_snapshot(
f.sync_all()?;
maybe_fail!("snap write post");
+ // This is important to avoid a race condition encountered on macos APFS
+ // where the rename below fails due to the metadata for path_1 not being
+ // present yet.
+ drop(f);
+
trace!("wrote snapshot to {}", path_1.to_string_lossy());
maybe_fail!("snap write mv");
