WebDAV sync: fix infinite 412 loop on weak ETags (#15715)

This commit is contained in:
Alejandro Lorite Mora authored and GitHub committed 2026-07-22 18:35:37 +03:00
1 parent 1c64298c9f
commit 213e0220b6
3 files changed
+18 -1

No files matched your search

+6 -1
View File
@@ -151,12 +151,17 @@ function SyncService.sync(server, file_path, sync_cb, is_silent)
end
local code_response = 412 -- If-Match header failed
local etag
-- Bound the If-Match retry loop so a persistently failing 412 (e.g. a server
-- that only ever returns a weak ETag which can't satisfy If-Match) can't hang
-- the app indefinitely; give up after a few tries and report failure.
local max_tries, tries = 5, 0
local api = server.type == "dropbox" and require("apps/cloudstorage/dropboxapi") or require("apps/cloudstorage/webdavapi")
local token = server.password
if server.type == "dropbox" and not (server.address == nil or server.address == "") then
token = api:getAccessToken(server.password, server.address)
end
while code_response == 412 do
while code_response == 412 and tries < max_tries do
tries = tries + 1
os.remove(income_file_path)
if server.type == "dropbox" then
local url_base = server.url:sub(-1) == "/" and server.url or server.url.."/"
+6
View File
@@ -175,6 +175,12 @@ end
function WebDavApi:uploadFile(file_url, user, pass, local_path, etag)
socketutil:set_timeout(socketutil.FILE_BLOCK_TIMEOUT, socketutil.FILE_TOTAL_TIMEOUT)
-- If-Match uses strong comparison (RFC 7232 §3.1), so a weak validator
-- (W/"…", returned e.g. for gzip-compressed responses) can never match and
-- would 412 forever. Strip the weak prefix; proxies keep the same value.
if type(etag) == "string" then
etag = etag:gsub("^%s*[Ww]/", "")
end
local code, _, status = socket.skip(1, http.request{
url = file_url,
method = "PUT",
@@ -163,6 +163,12 @@ end
function WebDavApi.uploadFile(file_url, user, pass, local_path, etag)
socketutil:set_timeout(socketutil.FILE_BLOCK_TIMEOUT, socketutil.FILE_TOTAL_TIMEOUT)
-- If-Match uses strong comparison (RFC 7232 §3.1), so a weak validator
-- (W/"…", returned e.g. for gzip-compressed responses) can never match and
-- would 412 forever. Strip the weak prefix; proxies keep the same value.
if type(etag) == "string" then
etag = etag:gsub("^%s*[Ww]/", "")
end
local code, _, status = socket.skip(1, http.request{
url = file_url,
method = "PUT",