Skip to content

core: owned-file removal still unlinks by name after its identity check #472

Closed

Description

@ElbertePlinio

Found while reviewing the fix for #463.

DirHandle.unlinkOwnedFile in packages/core/src/dir-handle.ts checks the entry's identity with lstat, then calls unlinkChild by name. A file that replaces the entry between those two syscalls is removed. In session prune, a replaced xvfb.log or stopped.json is then lost, the directory is removed, and prune reports the id. A review probe that swapped the file at that point confirmed this. POSIX has no unlink by inode, so the fix in #463 documents this window in unlinkStaleFile. Session prune, evidence export and screenshots all use this helper.

Two smaller points from the same review:

  • retainSessionLogs in packages/core/src/session-retention.ts removes lease staging files and orphan marker temp files by name after an lstat, with no identity check.
  • The helper's error, "Atomic write entry was replaced", names atomic writes in every caller. In session prune the entry is a retained session file.

A fix could move the entry to a unique quarantine name, check the moved entry's identity, and only then unlink it. A mismatch would put the entry back with link, which cannot overwrite, or keep it under a name that prune does not know. Later runs would need to recover quarantine names left by a crash.

  • Remove an owned file only when the removed entry is the checked one, or keep a replacement that arrives at any point
  • Recover entries left under a quarantine name by a crash
  • Apply the same check to the staging cleanup in retainSessionLogs
  • Give the error a message that fits each caller
  • Test a replacement at the last step, before and after
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions