Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(recording): finalize and recover recordings stored on exFAT
Aatman Jain (AJ)3cd8216ccb4e
diff --git a/crates/recording/src/recovery.rs b/crates/recording/src/recovery.rsindex 9eddbcbeb..342857aca 100644--- a/crates/recording/src/recovery.rs+++ b/crates/recording/src/recovery.rs@@ -2828,6 +2828,17 @@ fn reject_recovery_link(metadata: &std::fs::Metadata) -> Result<(), RecoveryErroOk(())}+/// On exFAT/FAT volumes macOS keeps each file's extended attributes (every+/// file Cap writes gets `com.apple.provenance`) in a visible `._<name>`+/// AppleDouble sibling, and creates the destination's own sibling as soon as a+/// copy creates `<name>`. Copying the source's sibling then fails with EEXIST,+/// every time: https://github.com/CapSoftware/Cap/issues/2386. Cap never+/// writes `._` names, so these entries are filesystem bookkeeping, not+/// recording data.+fn is_apple_double(name: &std::ffi::OsStr) -> bool {+ name.as_encoded_bytes().starts_with(b"._")+}+fn copy_recovery_input(source: &Path, destination: &Path) -> Result<(), RecoveryError> {copy_recovery_input_with_durability(source, destination, RecoveryCopyDurability::Durable)}@@ -2843,6 +2854,9 @@ fn copy_recovery_input_with_durability(std::fs::create_dir(destination)?;for entry in std::fs::read_dir(source)? {let entry = entry?;+ if is_apple_double(&entry.file_name()) {+ continue;+ }copy_recovery_input_with_durability(&entry.path(),&destination.join(entry.file_name()),@@ -2936,7 +2950,10 @@ fn recovery_snapshot(project: &Path) -> Result<RecoverySnapshot, RecoveryError>if metadata.is_dir() {let _ = entries.insert(relative, None);for entry in std::fs::read_dir(path)? {- visit(root, &entry?.path(), entries, files, bytes)?;+ let entry = entry?;+ if !is_apple_double(&entry.file_name()) {+ visit(root, &entry.path(), entries, files, bytes)?;+ }}} else if metadata.is_file() {files.push(path.to_path_buf());@@ -3129,7 +3146,10 @@ fn recovery_publication_segments_stamp();if metadata.is_dir() {for entry in std::fs::read_dir(path)? {- visit(root, &entry?.path(), entries, version)?;+ let entry = entry?;+ if !is_apple_double(&entry.file_name()) {+ visit(root, &entry.path(), entries, version)?;+ }}}Ok(())@@ -6213,6 +6233,30 @@ mod transactional_recovery_tests {}}+ #[test]+ fn recovery_copies_and_snapshots_skip_apple_double_siblings() {+ let dir = tempfile::tempdir().unwrap();+ let project = dir.path().join("project");+ let segment = project.join("content/segments/segment-0");+ std::fs::create_dir_all(&segment).unwrap();+ std::fs::write(segment.join("display.mp4"), b"media").unwrap();+ let before = recovery_snapshot(&project).unwrap();++ let apple_double = b"\x00\x05\x16\x07";+ std::fs::write(segment.join("._display.mp4"), apple_double).unwrap();+ std::fs::write(project.join("content/segments/._segment-0"), apple_double).unwrap();+ assert_eq!(recovery_snapshot(&project).unwrap(), before);++ let staged = dir.path().join("staged");+ copy_recovery_input(&project.join("content"), &staged).unwrap();+ assert_eq!(+ std::fs::read(staged.join("segments/segment-0/display.mp4")).unwrap(),+ b"media"+ );+ assert!(!staged.join("segments/segment-0/._display.mp4").exists());+ assert!(!staged.join("segments/._segment-0").exists());+ }+#[test]fn recovery_lock_refuses_concurrent_attempt_without_touching_first_lock() {let dir = tempfile::tempdir().unwrap();diff --git a/crates/recording/src/recovery/preparing_projection.rs b/crates/recording/src/recovery/preparing_projection.rsindex f1b087c32..38a5bed98 100644--- a/crates/recording/src/recovery/preparing_projection.rs+++ b/crates/recording/src/recovery/preparing_projection.rs@@ -11,7 +11,7 @@ use cap_project::{StudioRecordingStatus, VideoMeta,};-use super::{IncompleteRecording, RecoveryManager, reject_recovery_link};+use super::{IncompleteRecording, RecoveryManager, is_apple_double, reject_recovery_link};use crate::studio_recording::CleanStoppedStudioClaim;const MAX_JSON_BYTES: u64 = 8 * 1024 * 1024;@@ -451,6 +451,9 @@ impl Inventory {std::fs::read_dir(root.join(&directory)).map_err(|error| error.to_string())?{let entry = entry.map_err(|error| error.to_string())?;+ if is_apple_double(&entry.file_name()) {+ continue;+ }let relative = directory.join(entry.file_name());local_relative(&relative)?;entry_count += 1;@@ -767,6 +770,9 @@ fn validate_cursor_inventory(.collect();for entry in std::fs::read_dir(project.join(directory)).map_err(|error| error.to_string())? {let entry = entry.map_err(|error| error.to_string())?;+ if is_apple_double(&entry.file_name()) {+ continue;+ }let path = directory.join(entry.file_name());checked_metadata(project, &path, false)?;if !remaining.remove(&path) {@@ -1115,6 +1121,22 @@ mod tests {);}+ #[test]+ fn preparing_projection_ignores_apple_double_siblings() {+ let fixture = Fixture::new(1);+ let content = fixture.directory.path().join("content");+ let apple_double = b"\x00\x05\x16\x07";+ std::fs::write(content.join("segments/._segment-0"), apple_double).unwrap();+ std::fs::write(+ content.join("segments/segment-0/display/._init.mp4"),+ apple_double,+ )+ .unwrap();+ std::fs::create_dir(content.join("cursors")).unwrap();+ std::fs::write(content.join("cursors/._cursor_0.png"), apple_double).unwrap();+ assert!(fixture.project().is_ok());+ }+#[test]fn preparing_projection_compares_writer_float_representation_and_rejects_unknown_fields() {let fixture = Fixture::new(1);