From 6eb2c52ef4085dfe1244b2b9f23bdc3a8e52ec28 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 21 May 2022 11:10:44 +0800 Subject: improve is_connected --- .../private/service/remote_cache/client.lua | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'xmake/modules/private/service/remote_cache/client.lua') 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 -- cgit v1.3.1