WebDAV: a parked replacement (.cairn-replace-*) left by a crash hides the only copy of a file #954

Closed
opened 2026-10-17 13:17:53 +00:00 by Cordy · 1 comment
Owner

Found while implementing the temp-file sweeper for #939 (batch 1, 2026-10-17).

What happens

A WebDAV overwrite parks the current file under a hidden name (<name>.cairn-replace-<token>, storage.IsReplaceStaging) while the replacement is placed. If Cairn crashes between parking and placing or restoring, that parked file can be the only copy of the user's file:

  • it is hidden from every listing;
  • it counts nowhere;
  • nothing restores it at the next start.

The #939 sweeper deliberately leaves these files alone. Deleting one by age would destroy data, because a rename keeps the old mtime.

Expected

At start, Cairn finds parked replacements:

  • If the original name is missing, it moves the parked file back to the original name.
  • If both the original and the parked file exist, it keeps both: it restores the parked one as a version, or as a visible "(recovered)" sibling.
  • It logs one WARN line per recovery.

To do

  • Read the WebDAV replace code path and decide which recovery is safe in each state.
  • Write a crash-recovery test for each state, on posix and s3.
Found while implementing the temp-file sweeper for #939 (batch 1, 2026-10-17). ## What happens A WebDAV overwrite parks the current file under a hidden name (`<name>.cairn-replace-<token>`, `storage.IsReplaceStaging`) while the replacement is placed. If Cairn crashes between parking and placing or restoring, that parked file can be the only copy of the user's file: - it is hidden from every listing; - it counts nowhere; - nothing restores it at the next start. The #939 sweeper deliberately leaves these files alone. Deleting one by age would destroy data, because a rename keeps the old mtime. ## Expected At start, Cairn finds parked replacements: - If the original name is missing, it moves the parked file back to the original name. - If both the original and the parked file exist, it keeps both: it restores the parked one as a version, or as a visible "(recovered)" sibling. - It logs one WARN line per recovery. ## To do - Read the WebDAV replace code path and decide which recovery is safe in each state. - Write a crash-recovery test for each state, on posix and s3.
Author
Owner

Two more cases from the batch 1 (#939) reviews, for whoever picks this up.

What batch 1 already changed:

  • Users can no longer create names containing .cairn-replace-. The reserved layer refuses them as a destination; only WebDAV's own parking, which carries an internal marker, may create them.
  • The quota walk now counts hidden entries, so a leftover parked entry is charged to the cap.

Still open here:

  1. Parent move during a park: if a user moves the parent folder away while an overwrite has an entry parked, the WebDAV handler's final delete (internal/dav/dav.go:571) finds nothing and ignores that silently. The parked entry is left under the moved parent. It counts toward the cap, but the user can neither see nor delete it. Recovery at start should cover this case too.
  2. s3 folder copies: a folder copy on s3 still copies tagged children, because they are not hidden there. A user copy can therefore create a tagged name that WebDAV's parking did not make. The recovery must not assume every tagged name on s3 is a crash leftover.
Two more cases from the batch 1 (#939) reviews, for whoever picks this up. **What batch 1 already changed:** - Users can no longer create names containing `.cairn-replace-`. The `reserved` layer refuses them as a destination; only WebDAV's own parking, which carries an internal marker, may create them. - The quota walk now counts hidden entries, so a leftover parked entry is charged to the cap. **Still open here:** 1. **Parent move during a park:** if a user moves the parent folder away while an overwrite has an entry parked, the WebDAV handler's final delete (`internal/dav/dav.go:571`) finds nothing and ignores that silently. The parked entry is left under the moved parent. It counts toward the cap, but the user can neither see nor delete it. Recovery at start should cover this case too. 2. **s3 folder copies:** a folder copy on s3 still copies tagged children, because they are not hidden there. A user copy can therefore create a tagged name that WebDAV's parking did not make. The recovery must not assume every tagged name on s3 is a crash leftover.
Cordy closed this issue 2026-10-27 12:22:53 +00:00
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#954
No description provided.