Skip to content

libobs: Preserve serialized files when safe saves fail - #71

Merged
zackees merged 2 commits into
masterfrom
fix/serializer-safe-replace
Oct 10, 2026
Merged

zackees merged 2 commits into
masterfrom
fix/serializer-safe-replace

Conversation

@zackees

@zackees zackees commented Oct 9, 2026

Copy link
Copy Markdown
Member

Supersedes #36 (by @Mquarmoc), rebased onto current master as a RED → GREEN pair.

RED — c878e8f20 test(libobs): RED safe file-serializer failure tests

Master already has a test_file_serializer.c characterization test, which stays unchanged. The PR's tests move to a new Linux-only test/cmocka/test_file_serializer_safe.c (/dev/full). Against master:

safe_save_preserves_original_on_flush_failure   original replaced (64 != 8 bytes)
safe_save_preserves_original_on_write_failure   original replaced (64 != 8 bytes)
safe_save_preserves_original_on_rename_failure  original deleted
safe_save_replaces_original                     passes

GREEN — 16c8d1748 libobs: Preserve serialized files when safe saves fail

file_output_serializer_free now checks ferror and fclose. On success it installs the temporary file with os_safe_replace, which handles a missing target on both nix and Windows, instead of os_unlink followed by os_rename. Otherwise it logs a warning and leaves the original alone.

./unittest: 27/27 cmocka with ENABLE_RUST_LIBOBS OFF and ON, identical exported symbols. Local gate stamped.

Note: #66 (file-serializer Rust port) will need to carry this behavior; test_file_serializer_safe becomes a Tier 2 check for it.

zackees and others added 2 commits October 9, 2026 17:14
Safely serialize to a temporary file symlinked to /dev/full, or whose
rename fails: an immediate write error, a buffered flush error and a
failed replacement must each leave the original file intact, and a
successful save must replace it and remove the temporary file. The
tests live beside the unchanged test_file_serializer characterization
test, Linux-only for /dev/full.

Rebased from #36 onto current master.

Co-Authored-By: Mquarmoc <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
file_output_serializer_free ignored write and flush errors and then
unlinked the destination before renaming the temporary file over it, so
a full disk installed a truncated file and a failed rename lost the
original entirely. Check ferror and fclose, replace through
os_safe_replace only on success, and log a failed save.

Fixes #36

Co-Authored-By: Mquarmoc <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=221c837eae4bc17d00f21dfb5c3f41d4e82ada8b secs=28 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791591328,"gate":"rust/all/fmt","host":"linux-x86_64","key":"2bfcc62af1ced1616cb453b0ff44edb11ac9a067bd015231c277ec3d90cf8ca1","lane":"lint","parents":["456bf8e160c7e710264c338c53514f42eb66a339"],"secs":9,"stamp":"07e30a3915b1acd9508bd08f758277e8","tree":"221c837eae4bc17d00f21dfb5c3f41d4e82ada8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791591328,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"2bfcc62af1ced1616cb453b0ff44edb11ac9a067bd015231c277ec3d90cf8ca1","lane":"lint","parents":["456bf8e160c7e710264c338c53514f42eb66a339"],"secs":9,"stamp":"9268efd573f8779f2cb907efa407aedc","tree":"221c837eae4bc17d00f21dfb5c3f41d4e82ada8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791591328,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"2931c01a2b511eb9a87a9771a8f991aeb5ded7821e822be3ed33db850eff2c54","lane":"rust-test","parents":["456bf8e160c7e710264c338c53514f42eb66a339"],"secs":5,"stamp":"aaa15bdfc341d1d1b18abd9f8d2dbf42","tree":"221c837eae4bc17d00f21dfb5c3f41d4e82ada8b","v":1,"via":"run"}
Ci-Attestation: {"at":1791591328,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"66075c26f9bafd72ec84ad7353e4120ff921d9678b1eb00590909c7e96be34f1","lane":"tier2-linux","parents":["456bf8e160c7e710264c338c53514f42eb66a339"],"secs":14,"stamp":"40faec51a8a855ba8abbffeca9fba51a","tree":"221c837eae4bc17d00f21dfb5c3f41d4e82ada8b","v":1,"via":"run"}
@zackees
zackees force-pushed the fix/serializer-safe-replace branch from 16c8d17 to 2cfa79d Compare October 10, 2026 00:15
@zackees
zackees merged commit 012d183 into master Oct 10, 2026
22 checks passed
@zackees zackees mentioned this pull request Oct 10, 2026
7 tasks done
zackees added a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
file-serializer.c now replaces safe saves through os_safe_replace (obs-rust#71),
so the oracle host provides it, following platform-nix.c and
platform-windows.c. fseeko/ftello are POSIX and hidden by -std=c11;
GCC 14 rejects the implicit declarations, so expose them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees added a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
Mirror test_file_serializer_safe.c (obs-rust#71) in Tier 1: a write to a
/dev/full temporary file and a vanished temporary file must both leave
the original destination intact. The port still unlinks the destination
and renames the temporary file over it regardless of errors, so with
ENABLE_RUST_LIBOBS=ON test_file_serializer_safe fails all three failure
cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees added a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
Follow the C fix in obs-rust#71. Output buffers writes like fwrite, records a
short write or failed flush, and on drop installs the temporary file
with a single rename only after a clean write, instead of unlinking the
destination and renaming over it regardless of errors. A full disk or a
failed rename now leaves the original intact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=abdadacf8c512ab9ee957f8404e624d40569edee secs=180 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791594564,"gate":"rust/all/fmt","host":"linux-x86_64","key":"3ac7a0f9758cc2eb386d1aba1d4332bcd8c0f397f2699e63c137383d2e21e7f9","lane":"lint","parents":["1cf9795603dcc49bdd4a722f5ebaea19b259b12e"],"secs":110,"stamp":"94b1cacf62926ded5589edad70f6862e","tree":"abdadacf8c512ab9ee957f8404e624d40569edee","v":1,"via":"run"}
Ci-Attestation: {"at":1791594564,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"3ac7a0f9758cc2eb386d1aba1d4332bcd8c0f397f2699e63c137383d2e21e7f9","lane":"lint","parents":["1cf9795603dcc49bdd4a722f5ebaea19b259b12e"],"secs":110,"stamp":"78f876756e10f4207fc504529f0a8bb6","tree":"abdadacf8c512ab9ee957f8404e624d40569edee","v":1,"via":"run"}
Ci-Attestation: {"at":1791594564,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"aee2b0321da147a1d4d0f179081b551d04abfa54b3dc92d424ad7974440f522d","lane":"rust-test","parents":["1cf9795603dcc49bdd4a722f5ebaea19b259b12e"],"secs":28,"stamp":"5fb9c3fe2d98bcc8abaf1b178f1e73d0","tree":"abdadacf8c512ab9ee957f8404e624d40569edee","v":1,"via":"run"}
Ci-Attestation: {"at":1791594564,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"fd43799a8129adc9c4441152fba8db4164aab102fd8d43265bd593169fffa2cb","lane":"tier2-linux","parents":["1cf9795603dcc49bdd4a722f5ebaea19b259b12e"],"secs":42,"stamp":"30be8ef02098e2219e20b34bd71cd6d7","tree":"abdadacf8c512ab9ee957f8404e624d40569edee","v":1,"via":"run"}
zackees added a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
file-serializer.c now replaces safe saves through os_safe_replace (obs-rust#71),
so the oracle host provides it, following platform-nix.c and
platform-windows.c. fseeko/ftello are POSIX and hidden by -std=c11;
GCC 14 rejects the implicit declarations, so expose them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees added a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
Mirror test_file_serializer_safe.c (obs-rust#71) in Tier 1: a write to a
/dev/full temporary file and a vanished temporary file must both leave
the original destination intact. The port still unlinks the destination
and renames the temporary file over it regardless of errors, so with
ENABLE_RUST_LIBOBS=ON test_file_serializer_safe fails all three failure
cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees added a commit to nathan-v/obs-studio that referenced this pull request Oct 10, 2026
Follow the C fix in obs-rust#71. Output buffers writes like fwrite, records a
short write or failed flush, and on drop installs the temporary file
with a single rename only after a clean write, instead of unlinking the
destination and renaming over it regardless of errors. A full disk or a
failed rename now leaves the original intact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=fcf1cb0bdb4abc27e9d34fe187941805188dcae0 secs=83 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791594782,"gate":"rust/all/fmt","host":"linux-x86_64","key":"c73e811b613c4ea37b837bf9f54f9f316207792d1e5c5b9be7f477eb0e01b927","lane":"lint","parents":["3e595ef9ff93286bf5b6a6f3023c750d328dec24"],"secs":28,"stamp":"58051c4640b294d4cac649658c2c39c2","tree":"fcf1cb0bdb4abc27e9d34fe187941805188dcae0","v":1,"via":"run"}
Ci-Attestation: {"at":1791594782,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"c73e811b613c4ea37b837bf9f54f9f316207792d1e5c5b9be7f477eb0e01b927","lane":"lint","parents":["3e595ef9ff93286bf5b6a6f3023c750d328dec24"],"secs":28,"stamp":"c02d0c41fac01b88105f8a282574db34","tree":"fcf1cb0bdb4abc27e9d34fe187941805188dcae0","v":1,"via":"run"}
Ci-Attestation: {"at":1791594782,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"9d7df3a023b40aa8216e052722ab7cc7d37469f720fb78c495f0c7f7c105f1bc","lane":"rust-test","parents":["3e595ef9ff93286bf5b6a6f3023c750d328dec24"],"secs":18,"stamp":"d931f130ec57616189be2d03ba13d832","tree":"fcf1cb0bdb4abc27e9d34fe187941805188dcae0","v":1,"via":"run"}
Ci-Attestation: {"at":1791594782,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"9338b4f97214c3bbc516bb75440c537403b08a3d8d2e9095949ec77be6b6c923","lane":"tier2-linux","parents":["3e595ef9ff93286bf5b6a6f3023c750d328dec24"],"secs":37,"stamp":"2a152f1bbd28b20fe4d8b44bb44cff2d","tree":"fcf1cb0bdb4abc27e9d34fe187941805188dcae0","v":1,"via":"run"}
@zackees
zackees deleted the fix/serializer-safe-replace branch October 26, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant