Conversation
…vice snapshot) WebDAV sync failed with "WebDAV PUT failed for /readany/sync/device-xxx.json: 404 Not Found" on servers where ensureDirectories() silently no-oped: mkcol treated 409 (intermediate collection missing) as success, and ensureDirectory skipped creation whenever the error message merely contained "405"/"409". The device snapshot upload also bypassed the ensure-parent-and-retry fallback that put()/putFile() had, so the 404 surfaced straight to the UI. - WebDavClient.put(): on 404/409 force-create the parent collection chain and retry once, so every upload path (put/putJSON) self-heals - WebDavClient.mkcol(): 409 no longer counts as success — recovery does not trust the PROPFIND probe (real servers 409 while the parent probes as existing): force-MKCOL every ancestor plus the target (RFC 4918 9.3.1), retrying each once without the trailing slash for gateways that mishandle collection URIs - WebDavClient.ensureDirectory(): drop error-message string matching; memoize confirmed collections to cut redundant PROPFIND probes - WebDavClient.get/getText/delete/move: attach the HTTP status to failures (WebDavError, message format unchanged) so getJSON() detects 404 by status instead of matching "404" anywhere in the message/path - WebDavBackend: share one ensure-parent-and-retry helper across put/putFile/putJSON (putJSON previously had none) and create the legacy file/cover directories via ensureDirectory instead of bare mkcol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
WebDAV 同步报错:
WebDAV PUT failed for /readany/sync/device-xxx.json: 404 Not Found。应用启动时远程根目录/readany存在,但/readany/sync等子目录应由应用自行创建——目录创建逻辑实际执行了,却被错误的响应处理吞掉,静默失败。根因
WebDavClient.mkcol()把 409 当成功:RFC 4918 中 409 = 中间父目录缺失,原代码status === 405 || status === 409直接 return,导致在返回 409 的服务器上ensureDirectories()静默失败。ensureDirectory()按错误消息字符串跳过(消息含 "405"/"409" 就当目录已存在,路径含这些数字时误判)。WebDavBackend.putJSON()绕过了put()/putFile()的"确保父目录重试"兜底,设备快照恰好走这条路。getJSON()用message.includes("404")判定文件不存在,路径含 "404" 时会把服务器错误误判为文件缺失。修复
put():404/409 时强制逐级 MKCOL 父目录链并重试一次,所有上传路径自愈;mkcol():409 不再当成功,恢复不信任 PROPFIND 探测(存在服务器父目录探测为存在、MKCOL 子目录却 409),强制 MKCOL 每一级并追加无斜杠重试;ensureDirectory()删除字符串匹配,新增已确认集合记忆;getJSON按状态码判定 404;putWithDirectoryHeal();遗留目录改用ensureDirectory。验证
注:此次代码调整和PR信息由AI生成