X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fhttpclient%2Fluasrc%2Fhttpclient%2Freceiver.lua;h=55503f14ba7b7738ccd63f82362ee87bd9525db5;hp=e46595db6f064b991cd0a02a11c24217bac341a3;hb=96d988abb004f9a7f10fcf8441fe1a7399420f4b;hpb=33fe5b57d76b287bad42de085e63fe2130ba2be3 diff --git a/libs/httpclient/luasrc/httpclient/receiver.lua b/libs/httpclient/luasrc/httpclient/receiver.lua index e46595db6..55503f14b 100644 --- a/libs/httpclient/luasrc/httpclient/receiver.lua +++ b/libs/httpclient/luasrc/httpclient/receiver.lua @@ -23,19 +23,14 @@ module "luci.httpclient.receiver" local function prepare_fd(target) -- Open fd for appending - local file, code, msg = nixio.open(target, "r+") - if not file and code == nixio.const.ENOENT then - file, code, msg = nixio.open(target, "w") - if file then - file:flush() - end - end + local oflags = nixio.open_flags("wronly", "creat") + local file, code, msg = nixio.open(target, oflags) if not file then return file, code, msg end -- Acquire lock - local stat, code, msg = file:lock("ex", "nb") + local stat, code, msg = file:lock("tlock") if not stat then return stat, code, msg end @@ -208,7 +203,12 @@ function request_to_file(uri, target, options, cbs) end if cbs.on_header then - cbs.on_header(file, code, resp) + local stat = {cbs.on_header(file, code, resp)} + if stat[1] == false then + file:close() + sock:close() + return true, nil, nil, unpack(stat, 2) + end end local chunked = resp.headers["Transfer-Encoding"] == "chunked"