diff options
| author | ruki <[email protected]> | 2022-05-21 11:10:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-21 11:10:44 +0800 |
| commit | 6eb2c52ef4085dfe1244b2b9f23bdc3a8e52ec28 (patch) | |
| tree | bb7506c68b0a30712ef18fed1e87fe84e59e7e9f /xmake/modules | |
| parent | 51fd55be6e12e87add7dce302a1abf1eff047344 (diff) | |
improve is_connected
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/service/remote_cache/client.lua | 34 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_cache/server_session.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/private/service/stream.lua | 4 |
3 files changed, 26 insertions, 17 deletions
diff --git a/xmake/modules/private/service/remote_cache/client.lua b/xmake/modules/private/service/remote_cache/client.lua index 33f6ee886..a28927b33 100644 --- a/xmake/modules/private/service/remote_cache/client.lua +++ b/xmake/modules/private/service/remote_cache/client.lua @@ -371,22 +371,30 @@ end -- is connected? we cannot depend on client:init when run action function is_connected() - -- the current process is in service? we cannot enable it - if os.getenv("XMAKE_IN_SERVICE") then - return false - end - local projectdir = os.projectdir() - local projectfile = os.projectfile() - if projectfile and os.isfile(projectfile) and projectdir then - local workdir = path.join(project_config.directory(), "remote_cache") - local statusfile = path.join(workdir, "status.txt") - if os.isfile(statusfile) then - local status = io.load(statusfile) - if status and status.connected then - return true + local connected = _g.connected + if connected == nil then + -- the current process is in service? we cannot enable it + if os.getenv("XMAKE_IN_SERVICE") then + connected = false + end + if connected == nil then + local projectdir = os.projectdir() + local projectfile = os.projectfile() + if projectfile and os.isfile(projectfile) and projectdir then + local workdir = path.join(project_config.directory(), "remote_cache") + local statusfile = path.join(workdir, "status.txt") + if os.isfile(statusfile) then + local status = io.load(statusfile) + if status and status.connected then + connected = true + end + end end end + connected = connected or false + _g.connected = connected end + return connected end -- new a client instance diff --git a/xmake/modules/private/service/remote_cache/server_session.lua b/xmake/modules/private/service/remote_cache/server_session.lua index ee4b5b1f2..9437ccfb3 100644 --- a/xmake/modules/private/service/remote_cache/server_session.lua +++ b/xmake/modules/private/service/remote_cache/server_session.lua @@ -102,13 +102,10 @@ function server_session:push(respmsg) local stream = self:stream() local cachekey = body.filename local cachefile = path.join(self:cachedir(), cachekey:sub(1, 2), cachekey) - local cachefile_tmp = cachefile .. ".tmp" vprint("push cachefile(%s) ..", cachekey) - if not stream:recv_file(cachefile_tmp) then - os.tryrm(cachefile_tmp) + if not stream:recv_file(cachefile) then raise("recv %s failed!", cachefile) end - os.mv(cachefile_tmp, cachefile) end -- get file info diff --git a/xmake/modules/private/service/stream.lua b/xmake/modules/private/service/stream.lua index 095c773c4..78527927f 100644 --- a/xmake/modules/private/service/stream.lua +++ b/xmake/modules/private/service/stream.lua @@ -352,6 +352,10 @@ end function stream:recv_file(filepath) local size, flags = self:recv_header() if size then + -- empty file? we need not create file + if size == 0 then + return size + end if bit.band(flags, HEADER_FLAG_COMPRESS_LZ4) == HEADER_FLAG_COMPRESS_LZ4 then return self:_recv_compressed_file(lz4.decompress_stream(), filepath, size) end |
