On an S3 server that refuses If-Match (Aliyun OSS answers 400
NotImplemented), put falls back to HEAD then an unconditional PUT. Two
computers writing in the moment between both pass the HEAD, both are
told they wrote, and the later file is kept. Worse, the loser's next sync
then took the winner's file as having seen its own: its st.Remote was the
file it wrote, so its changed parts looked unchanged here and changed
there, and the old parts were brought in over its own changes. The edit
was lost on the server and on the computer that made it.
- version.Blind marks a write the server didn't check (s3.go's fallback).
- state.Blind keeps, for such a write, the file's sum and the remote and
local part hashes from before it. The next sync that reads another
file than that one merges from before the write. What this computer
changed counts as changed again and goes back up beside the other's.
A 304 or the same file clears it. Restore and Upload clear it.
- docs/reference.md says what happens on such a server.
No compare-and-swap exists on OSS, so the race itself isn't closed: the
other computer's file is kept for up to one sync interval (3 minutes)
before this computer's change is merged back. The reporter's AppendObject
journal would close it but needs every computer upgraded and OSS-only
signing. If the other computer saw this one's write and then changed the
same part again, the next sync can't tell that from a write that went
over it. It counts the part as changed on both sides: the newer stays,
the other is saved, and a notice says so. Nothing is lost.
Run:
- TestS3BlindWriteGoneOverIsMergedAgain (fake S3 with no conditional
writes, two computers): A renames a provider and B sets the theme, B's
PUT goes over A's, then A's next sync puts both on the server with no
conflict notice, B brings in the rename, and nothing more is written.
With the reset taken out (broken by hand), it fails: "A's rename here
after its next sync: \"DeepSeek\"".
- go test ./internal/davsync whole.
Not tried against real Aliyun OSS: the fake answers conditional PUTs the
way the reporter quotes OSS (NotImplemented).
JasonLeeForOnly's WebDAV sync failed with only "not a magpie backup" for
several versions, and nothing on the page got past it. A WebDAV GET of the
backup can come back as a body that isn't the file in several ways; each is
now reproduced with an httptest server that answers the way the real one
does:
Unpacked (WebDAV and S3): gzip with or without Content-Encoding (a proxy
that drops the header), x-gzip, zstd with or without the header, deflate
(zlib or raw), and a header that says gzip over a plain body. Bodies are
told by magic number; a backup is JSON, so either magic is never the file.
Brotli (br) can't be unpacked and is said as itself, with what to turn off.
Said, with no upload offered: an HTML page answered with 200 (Nextcloud
login after a redirect, Cloudflare Access, an AList/OpenList web app, an
rclone directory listing, a captive portal), with its <title> and the
host/path a redirect ended at (query, fragment and user dropped), and
where the WebDAV address is for 坚果云 and Nextcloud; an XML answer, by its
root element.
Said, with Upload as the way out: an empty (0-byte) file, a backup cut
short or damaged (the automatic rebuild is unchanged and still goes first
when its rules allow), another app's file ("format": "…"), other JSON,
and any other file by its content type. Messages carry the size, kind and a
page title only, never the file's contents.
backup.Open now tells ErrNotBackup (doesn't begin like a backup) from
ErrCorrupt (begins like one, cut short). The status carries the kind as
serverFile; Settings › Sync and backup says it in the reader's language,
wraps it whole, and shows "Upload this computer's setup" only when the file
may be replaced. davsync.Upload (POST /api/davsync/upload, `magpie webdav
upload`, `magpie s3 upload`) asks first in the GUI, re-reads the file,
refuses a backup this computer opens, one sealed with another passphrase,
a newer magpie's, a page and an XML answer, keeps the server's copy in the
sync folder (0600, newest 5) and writes nothing if that fails, then writes
with If-Match on the version read. New strings in en, zh, zh-TW, ja, de.
Verified: internal/davsync/not_backup_test.go (TestReadCompressedBackup,
TestReadBrotliSaid, TestServerAnswerSaid, TestCutBackupSaidAndUploaded,
TestS3ReadCompressedObject; Upload-only parts stripped to compile) fails
on e4a90aa6 for every compressed case but "gzip said", Brotli, every
server-answer case, the cut case and S3 gzip, and passes here. Dropping
the Replace check in Upload turns the page/XML cases red ("Upload wrote
over a page"). gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows
-tags nogui on ., davsync, backup, gui; full go test -tags nogui ./... ok;
-race on davsync and backup ok. GUI: sync-not-backup.test.cjs (en, zh,
zh-TW, ja, de; 900 and 440px), sync-*, s3-sync, gui-de, gui-ja, gui-zh-tw,
click-scroll in Chromium and WebKit, 81 pass. Not tried against a real
WebDAV server or on the Windows box; the reporter's server is unknown.
Note: 2018882e on main carries this subject by mistake (another session read a shared message file); it holds only GTK DPI code. This commit is the actual WebDAV change.
What: dav.get sends Accept-Encoding: identity, and unpacks a body a server
gzips anyway (Go only unpacks what it asked gzip for itself).
Why: Go's client asks for gzip on every GET. InfiniCLOUD's (TeraCloud's)
WebDAV is Apache mod_dav_fs, whose PUT answers with no ETag (mod_dav.c's
dav_created: "### insert an ETag header?"), so the sync after the first
reads the file in full and pushes over the ETag that read gave. Apache's
mod_deflate (DeflateAlterETag AddSuffix, the default) gives the gzip copy
"<etag>-gzip", which no If-Match on the file matches: every write after the
first was 412, the retry read the same -gzip tag, and the state left the
local change pending, so every sync after failed. A read asked for as it
is gets the file's own ETag. nginx-style proxies that weaken the ETag
(W/"...") on gzip are covered by the same change.
TeraCloud behaviour assumed: seen without an account on 2026-10-09 against
https://domi.teracloud.jp: OPTIONS /dav/ says Server: Apache and
DAV: <http://apache.org/dav/propset/fs/1>; GET / with Accept-Encoding: gzip
gives ETag "fb-5d88268abcf08-gzip" + Content-Encoding: gzip, without it
"fb-5d88268abcf08"; GET with If-Match the -gzip tag is 412, with the plain
tag 200. Not seen: that mod_deflate compresses files under /dav/ (needs an
account). The fake (apacheDAV in teracloud_test.go) does: no ETag on PUT,
gzip + "-gzip" ETag on a GET that accepts gzip, If-Match strong against
the file's own ETag.
Real conflict detection is unchanged: If-Match is still sent with the
version read; TestSyncTeraCloudStillSeesOtherWrites lands another
computer's write between a's read and write on the same fake and checks
the 412, the merge over it, and b's file kept aside.
Run:
- new tests fail on the old code: without identity,
TestSyncTeraCloudGzipETag "sync 2 after the first: the file on the
server changed meanwhile (2 writes refused, 2 reads sent gzip)"; with
If-Match dropped, TestSyncTeraCloudStillSeesOtherWrites "write over a
replaced version: <nil>, want errChanged"; without the unpack,
TestDAVGetGzipAnyway reads gzip bytes. All pass restored.
- sandbox HOME, pinned caches: go test -race -tags nogui ./internal/davsync/
./internal/gui/ . ok; -race -count=5 on the davsync sync/conditional/
short-write/Nutstore tests ok
- gofmt -l clean; go vet (darwin, darwin nogui, linux nogui, windows) of
internal/davsync; go build darwin, linux nogui, windows
Not run: a real TeraCloud account.
After each PUT, check read the file's size from a HEAD and called anything
shorter a cut write. On 坚果云 every usage write failed that way with 0
bytes kept, three tries each; the 0 can only have come from the HEAD's
Content-Length, since a 6869-byte body that the PUT sends with its
Content-Length (not chunked) isn't cut by a dropping network three times
running. A HEAD that says short is now asked again of PROPFIND (Depth 0)
getcontentlength, the size WebDAV clients of 坚果云 read. The write counts
as kept when that size is whole. When PROPFIND gives no size, the HEAD's
stands. A real cut write is still told as cut, with the bytes PROPFIND
says were kept. The extra request is made only after a short HEAD, so
坚果云's request limit isn't spent on servers whose HEAD is right. The
backup's own PUT goes through the same check, so a 坚果云 user whose
setup changes would have hit the same error on the main sync.
Settings > Sync put "Couldn't share usage: …" in the same grey line as
"Synced · host", so it read as part of a sync that went fine. It is now a
line of its own under the status, in red, wrapped whole at 440px. The CLI
already printed it on its own line.
Verified: TestNutstoreHeadSaysNoLength and TestNutstoreBackupWrite use a
fake 坚果云: HEAD Content-Length: 0, real getcontentlength on PROPFIND,
409 for a read in a missing folder, a chunked PUT refused. Whole writes
sync with no usage error, and each write goes once with one HEAD and one
PROPFIND. A tunnel that keeps half is still told as cut, with the half it kept.
On the old dav.go all three fail ("the WebDAV server kept 0 of 536 bytes
of magpie.magpie-backup", "kept 0 of 6869"). TestDAVShortWrite and
TestUsageSharedShortWrite/TestUsageSyncShortWrite pass unchanged.
sync-usage-error.test.cjs runs in Chromium and WebKit, en/zh/ja/de, at
900 and 440px, and fails on the old app.js ("the status line carries no
usage error: 14:46 已同步 · dav.jianguoyun.com · 用量未能共享:…"). The
sync-*, s3-sync, usage-computers, gui-ja, gui-de, gui-zh-tw, i18n-keys
and click-scroll tests pass, 78/78. go test -tags nogui -count=1
./internal/davsync ./internal/gui pass under a temp HOME. go vet passes
on darwin, GOOS=linux and GOOS=windows. Not tried against a real 坚果云
account: that its HEAD answers 0 is inferred from the error, and that its
PROPFIND gives the real size is how its other WebDAV clients read sizes,
neither seen here.
Relays and tunnels cut long uploads short. Over a Cloudflare Tunnel
with a 3MB write this came up 2 of 3 times, and each time the client
saw it happen: the relay answered 502 or 423, which the sync reports
as itself. The quiet shape is a server that answers 2xx with half the
file on disk: every later sync then reads the half and fails as "not
a magpie backup", with no way to tell what actually went wrong.
A write is now looked at after it lands: a HEAD read of the backup is
compared with the size sent, a short write is retried over the version
the short one made (its ETag, from the PUT's answer or the HEAD's), and
after three tries reported as itself. A HEAD that can't be done — an
error, a 429 or 503, a non-200 — leaves the write unchecked: it landed
either way. Servers without HEAD check as before.
Co-authored-by: Claude Code <noreply@anthropic.com>