EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into fix/issue-1233-atomic-write-temp
midasmatterhorn963d8cc5e3dc
diff --cc crates/engine/src/tests_settings.rsindex 4ce956ca2,65e39b467..ee4c6ebe8--- a/crates/engine/src/tests_settings.rs+++ b/crates/engine/src/tests_settings.rs@@@ -571,54 -629,6 +629,42 @@@ fn atomic_write_survives_a_crash_mid_wrlet _ = std::fs::remove_dir_all(d);}- #[cfg(unix)]- #[test]- fn atomic_write_does_not_follow_a_planted_temporary_symlink() {- let d = tmp("atomic-link");- let f = d.join("p.ecproj");- let sentinel = d.join("sentinel.txt");- std::fs::write(&sentinel, b"precious").unwrap();- // Someone plants a symlink at the temporary name the write used to go through.- std::os::unix::fs::symlink(&sentinel, d.join("p.ecproj.tmp")).unwrap();- atomic_write(&f, b"new").unwrap();- assert_eq!(std::fs::read(&sentinel).unwrap(), b"precious", "a symlink at the temporary name is never followed");- assert_eq!(std::fs::read(&f).unwrap(), b"new");- let _ = std::fs::remove_dir_all(d);- }-- #[cfg(unix)]++/// A writer that is paused mid-temporary while another writer fully publishes to the same++/// destination must not let either one publish a mixture: the bounded, exclusively-created++/// temporaries keep the two writes apart (#1233). Unlike++/// `concurrent_atomic_writes_each_publish_a_whole_file`, this pins the interleaving++/// deterministically instead of sampling it under real contention.+#[test]+fn atomic_writes_in_parallel_never_publish_a_mixture() {+ use std::sync::{Arc, Barrier};+ let d = tmp("atomic-race");+ let f = d.join("p.ecproj");+ let a = vec![b'A'; 64];+ let b = vec![b'B'; 64];- // Writer A writes the first half of its temporary, then waits while writer B runs against- // the same destination, and only then finishes.++ // Writer A writes the first half of its temporary, then waits while writer B fully publishes++ // against the same destination, and only then finishes.+ let (half, published) = (Arc::new(Barrier::new(2)), Arc::new(Barrier::new(2)));+ let (f2, a2) = (f.clone(), a.clone());+ let (half2, published2) = (half.clone(), published.clone());+ let t = std::thread::spawn(move || {- atomic_write_with(&f2, &a2, |tmp, data| {++ atomic_write_with(&f2, &a2, |fh, data| {+ use std::io::Write;- let mut fh = std::fs::File::create(tmp)?;+ fh.write_all(&data[..32])?;+ half2.wait();+ published2.wait();+ fh.write_all(&data[32..])?;+ fh.sync_all()+ })+ });+ half.wait();+ atomic_write(&f, &b).unwrap();+ published.wait();- let _ = t.join();++ assert!(t.join().unwrap().is_ok(), "the paused writer still publishes");+ let got = std::fs::read(&f).unwrap();+ assert!(got == a || got == b, "the destination holds one complete write, never a mixture: {}", String::from_utf8_lossy(&got));+ let _ = std::fs::remove_dir_all(d);+}+#[test]fn autosave_rotates_through_max_versions() {let d = tmp("rotate");