Skip to content

Fix what the WebDAV review found - #21

Merged
ssenerg merged 1 commit into
mainfrom
review-webdav
Oct 25, 2026
Merged

ssenerg merged 1 commit into
mainfrom
review-webdav

Conversation

@ssenerg

@ssenerg ssenerg commented Oct 25, 2026

Copy link
Copy Markdown
Owner

This fixes all 15 findings from the review of the code merged since PR #17 (quotas, compose and WebDAV), most severe first.

Data safety

  • MOVE/COPY with Overwrite no longer deletes the destination before it acts. With the trash off, a move that then failed (rights inside a folder, quota, a busy file) used to lose the destination for good. Now:
    • A file replacing a file is done in one step (renameat or an atomic commit), as a PUT does.
    • Anything else sets the destination aside under a hidden name and puts it back if the move or copy fails.
    • A replaced folder goes to the trash only after the move or copy worked. A replaced file is gone, as one a PUT replaces.
    • So apps that save through a temp file plus MOVE (Office, Cyberduck/Mountain Duck temporary uploads) no longer fill the trash and the home's quota with every old version.
  • Case-only renames on case-insensitive file systems. A MOVE of a.txt to A.txt (e.g. Finder on an APFS-served folder) used to trash the file; it now renames it. The site's rename also failed (409, as both lock files were one) and now works. The checks for moving into itself or over what holds the source compare folded paths. Linux deployments weren't affected.

Correctness

  • If-Match / If-Unmodified-Since are honored by PUT (site and WebDAV), DELETE, MOVE, COPY and PROPPATCH, with strong ETag comparison (RFC 9110 §13.1).
  • PROPPATCH of a file's time now needs the right to overwrite it. Operators, who may only add files, could change others' mtimes.
  • X-OC-Mtime: accepted is sent only when the time was actually kept. A failed Chtimes is logged.
  • LOCK on a free name now creates the empty file RFC 4918 §7.3 requires; macOS ._ files are still not kept.
  • AppleDouble PUTs over 64 KiB are now read to the end (up to 64 MiB) instead of being cut off mid-upload.
  • WebDAV 405s now send WebDAV's Allow list instead of the site's.

Locks

  • Locks belong to their user: only they may refresh or UNLOCK them (403 otherwise).
  • Each user may hold 1,000 locks (10,000 in all), and the owner text is capped at 1 KiB, so one user can't pin memory or lock everyone out.
  • LOCK checks rights and the file system before taking the lock-table mutex.
  • PROPFIND reads the lock table once per request instead of once per entry.

Efficiency

  • Replacing a file takes the old file's size off the home's usage. It used to reset the count, so the next write walked the whole home and every trash note while holding the home's lock. This was quadratic for sync apps updating many files. The same now applies to resumable uploads and MOVEs that replace a file.
  • App-password sign-ins read last_used_at with the user and only write it once a minute, instead of an UPDATE on every request.

Cleanup

  • shownTime/isoTime replace about 10 copies of the time formatting.

Testing

  • New tests:
    • Safe replacing, with the trash on and off, where a failing MOVE or COPY must leave the destination untouched.
    • Quota after a replacing MOVE, and no recount after a replacing PUT.
    • Case-only renames on WebDAV and the site. This runs where the file system ignores case and skips on Linux.
    • Preconditions, lock ownership and limits, LOCK creating an empty file, an AppleDouble body over 64 KiB on a kept-alive connection, PROPPATCH by an operator, and the WebDAV Allow header.
  • go test -race ./... with Postgres passes on macOS, except TestLongNonASCIIPath, which fails only on macOS (on main too). Everything passes on Linux in golang:1.27.3-alpine.
  • I reran rclone v1.75.2 against a local server: bisync --resync, then an edit and a delete, check (6 matching files), modification times kept, a server-side moveto, and about. There were no server errors.

🤖 Generated with Claude Code

- A MOVE or COPY that replaces something no longer deletes it first: a
  file replaces a file in one step, as a PUT does, and anything else is
  set aside until the move or copy worked, and put back if it failed.
  With the trash off, a failed move used to lose the destination. A
  replaced file no longer goes to the trash either, so apps that save
  through a temporary file no longer fill the trash and the quota with
  every old version; a replaced folder still goes there.
- On file systems that find names in any case, a MOVE that changes only
  a name's case renames it, where it used to put the file in the trash;
  so does the site's rename, which refused. Nested moves are judged by
  folded paths.
- Replacing a file takes what it replaced off its home's usage, instead
  of counting the whole home and the trash again before the next write.
- PUT, DELETE, MOVE, COPY and PROPPATCH honor If-Match and
  If-Unmodified-Since.
- Locks belong to their users, who alone may refresh or end them; each
  user may hold 1,000, and an owner may be 1 KiB. Rights and the file
  system are checked before the lock table is held, and PROPFIND looks
  at it once. A lock of a free name makes an empty file (RFC 4918).
- macOS's ._ files are read to the end rather than cut off at 64 KiB.
- PROPPATCH of a file's time takes the right to overwrite it.
- X-OC-Mtime: accepted only when the time was kept.
- WebDAV's 405s list WebDAV's methods.
- App-password sign-ins write last_used_at at most once a minute.
- Shown times are formatted in one place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ssenerg
ssenerg merged commit 54e91a7 into main Oct 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant