diff options
| author | ruki <[email protected]> | 2022-04-16 11:33:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-16 11:33:09 +0800 |
| commit | f3ff3c8b3133102b8d818bf85f89cac4732f6eb8 (patch) | |
| tree | 02ba2635ae3d8410aaff52501d6efee9abf2506e /xmake/modules | |
| parent | ec42644f5fd2f522cb070f1ac0b33911b17f88ee (diff) | |
rename msg
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/service/message.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 33 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/server.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/session.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/private/service/sync_files.lua | 2 |
5 files changed, 62 insertions, 29 deletions
diff --git a/xmake/modules/private/service/message.lua b/xmake/modules/private/service/message.lua index 918175270..a097c20f4 100644 --- a/xmake/modules/private/service/message.lua +++ b/xmake/modules/private/service/message.lua @@ -30,8 +30,8 @@ message.CODE_DISCONNECT = 2 -- disconnect server message.CODE_CLEAN = 3 -- clean all cached files in server message.CODE_DATA = 4 -- send data message.CODE_RUNCMD = 5 -- run the given command in server -message.CODE_DIFFDIR = 6 -- diff files in directory between server and client -message.CODE_SYNCDIR = 7 -- sync files in directory between server and client +message.CODE_DIFF = 6 -- diff files between server and client +message.CODE_SYNC = 7 -- sync files between server and client message.CODE_PULL = 8 -- pull the given files from server -- init message @@ -59,9 +59,14 @@ function message:is_disconnect() return self:code() == message.CODE_DISCONNECT end --- is syncdir message? -function message:is_syncdir() - return self:code() == message.CODE_SYNCDIR +-- is diff message? +function message:is_diff() + return self:code() == message.CODE_DIFF +end + +-- is sync message? +function message:is_sync() + return self:code() == message.CODE_SYNC end -- is clean message? @@ -139,11 +144,18 @@ function new_disconnect(session_id) }) end --- new syncdir message -function new_syncdir(session_id, start) +-- new diff message +function new_diff(session_id) + return _new({ + code = message.CODE_DIFF, + session_id = session_id + }) +end + +-- new sync message +function new_sync(session_id) return _new({ - code = message.CODE_SYNCDIR, - start = start, + code = message.CODE_SYNC, session_id = session_id }) end diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index afe99bc1e..f1c03620a 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -102,9 +102,9 @@ function remote_build_client:connect() status.session_id = session_id self:status_save() - -- syncdir files + -- sync files if ok then - self:syncdir() + self:sync() end end @@ -148,7 +148,7 @@ function remote_build_client:disconnect() end -- sync server files -function remote_build_client:syncdir() +function remote_build_client:sync() assert(self:is_connected(), "%s: has been not connected!", self) local addr = self:addr() local port = self:port() @@ -159,12 +159,11 @@ function remote_build_client:syncdir() print("%s: sync files in %s:%d ..", self, addr, port) if sock then local stream = socket_stream(sock) - if stream:send_msg(message.new_syncdir(session_id, true)) and stream:flush() then + if stream:send_msg(message.new_sync(session_id)) and stream:flush() then local msg = stream:recv_msg() if msg and msg:success() then vprint(msg:body()) - self:_do_syncdir(msg:body().path, msg:body().branch) - if stream:send_msg(message.new_syncdir(session_id, false)) and stream:flush() then + if stream:send_msg(message.new_sync(session_id)) and stream:flush() then msg = stream:recv_msg() if msg and msg:success() then ok = true @@ -319,8 +318,26 @@ function remote_build_client:session_id() return self:status().session_id or hash.uuid():split("-", {plain = true})[1]:lower() end --- do syncdir -function remote_build_client:_do_syncdir(remote_path, remote_branch) +-- diff server files +function remote_build_client:_diff_files(stream) + assert(self:is_connected(), "%s: has been not connected!", self) + --[[ + if stream:send_msg(message.new_sync(session_id)) and stream:flush() then + local msg = stream:recv_msg() + if msg and msg:success() then + vprint(msg:body()) + if stream:send_msg(message.new_sync(session_id)) and stream:flush() then + msg = stream:recv_msg() + if msg and msg:success() then + ok = true + elseif msg then + errors = msg:errors() + end + end + elseif msg then + errors = msg:errors() + end + end]] end -- read stdin data diff --git a/xmake/modules/private/service/remote_build/server.lua b/xmake/modules/private/service/remote_build/server.lua index ff4e64dfc..181ab709f 100644 --- a/xmake/modules/private/service/remote_build/server.lua +++ b/xmake/modules/private/service/remote_build/server.lua @@ -70,8 +70,10 @@ function remote_build_server:_on_handle(stream, msg) elseif msg:is_disconnect() then session:close() self._SESSIONS[session_id] = nil - elseif msg:is_syncdir() then - session:syncdir(respmsg) + elseif msg:is_diff() then + session:diff(respmsg) + elseif msg:is_sync() then + session:sync(respmsg) elseif msg:is_clean() then session:clean() elseif msg:is_runcmd() then diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua index a8ca8a797..4158c42cc 100644 --- a/xmake/modules/private/service/remote_build/session.lua +++ b/xmake/modules/private/service/remote_build/session.lua @@ -61,11 +61,18 @@ function session:stream() return self._STREAM end --- sync directory -function session:syncdir(respmsg) +-- diff files +function session:diff(respmsg) local body = respmsg:body() - vprint("%s: %s sync files in %s ..", self, self:sourcedir(), body.start and "start" or "finish") - vprint("%s: %s sync files ok", self, body.start and "start" or "finish") + vprint("%s: %s diff files in %s ..", self, self:sourcedir()) + vprint("%s: %s diff files ok", self) +end + +-- sync files +function session:sync(respmsg) + local body = respmsg:body() + vprint("%s: %s sync files in %s ..", self, self:sourcedir()) + vprint("%s: %s sync files ok", self) end -- clean files @@ -198,11 +205,6 @@ function session:_send_data(data) end end --- get working branch of the source directory -function session:_source_branch() - return "remote_build" -end - function session:__tostring() return string.format("<session %s>", self:id()) end diff --git a/xmake/modules/private/service/sync_files.lua b/xmake/modules/private/service/sync_files.lua index 4721f9541..da002f8a4 100644 --- a/xmake/modules/private/service/sync_files.lua +++ b/xmake/modules/private/service/sync_files.lua @@ -24,7 +24,7 @@ import("private.service.config") import("private.service.remote_build.client", {alias = "remote_build_client"}) function main() - remote_build_client():syncdir() + remote_build_client():sync() end |
