Skip to content

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

Closed
Mquarmoc wants to merge 1 commit into
obs-rust:masterfrom
Mquarmoc:fix/serializer-safe-replace
Closed

Mquarmoc wants to merge 1 commit into
obs-rust:masterfrom
Mquarmoc:fix/serializer-safe-replace

Conversation

@Mquarmoc

@Mquarmoc Mquarmoc commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Description

Check stream errors and the close result before installing a safely serialized file. Reuse os_safe_replace rather than unlinking the destination before renaming the temporary file, and log failed saves.

Motivation and Context

The old safe-save cleanup could install an incomplete temporary file after a write/flush failure. It also deleted the destination before attempting rename, losing the old file if rename failed. Four new C tests cover immediate write errors, buffered flush errors, replacement failure, and successful replacement. The public API stays unchanged.

How Has This Been Tested?

The new failure cases were run against the original implementation and failed before the fix. The complete repository ./lint and ./unittest commands pass independently on this branch (Ubuntu 24.04 WSL host, Ubuntu 26.04 validation container):

  • clang-format 22.1.3, gersemi 0.25.0, Rust formatting and clippy.
  • Rust workspace unit, layout and C differential tests.
  • All seven C test executables with ENABLE_RUST_LIBOBS=OFF and ON.
  • DeckLink build in both configurations; identical libobs exports (1,752 symbols).

The new filesystem failure tests are Linux-only because they use /dev/full. Windows/macOS and an interactive OBS session were not run locally. These fixes detect buffered write errors; they do not add power-loss durability.

Types of changes

  • Bug fix (non-breaking change which fixes an issue).

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines.
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation (no public API or usage change).
  • I have used AI tooling in the creation of this PR.
  • I am an AI agent assisting with this pull request: Codex (GPT-6), responsible for the scoped audit, implementation, regression tests, code review and local validation.

Keep the previous file when a write, close, or rename fails.
Replace it through os_safe_replace only after a successful close,
instead of deleting it before renaming the temporary file.

Add Linux regressions for failures and successful replacement.
@zackees

zackees commented Oct 9, 2026

Copy link
Copy Markdown
Member

Rebased onto current master as a RED → GREEN pair in #71 (Co-Authored-By kept). Master already had a test_file_serializer.c characterization test, so your tests now live in test_file_serializer_safe.c. This PR can close once #71 lands.

zackees added a commit that referenced this pull request Oct 10, 2026
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]>
@zackees zackees closed this in 2cfa79d Oct 10, 2026
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.

2 participants