diff options
| author | ruki <[email protected]> | 2022-04-16 15:34:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-16 15:34:39 +0800 |
| commit | c72bd4e4c7727efb224085183fd15b965c023cbd (patch) | |
| tree | 6915ff58ab359677c29b54af2c4ce8d4432f30a9 | |
| parent | 012f809980180ead6b69e61d43d8de20e4727f97 (diff) | |
improve sync
| -rw-r--r-- | xmake/modules/private/service/message.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/client.lua | 24 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/session.lua | 4 |
3 files changed, 27 insertions, 12 deletions
diff --git a/xmake/modules/private/service/message.lua b/xmake/modules/private/service/message.lua index 3118b4a62..f0ff93f46 100644 --- a/xmake/modules/private/service/message.lua +++ b/xmake/modules/private/service/message.lua @@ -32,7 +32,7 @@ message.CODE_DATA = 4 -- send data message.CODE_RUNCMD = 5 -- run the given command in server 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 +message.CODE_PULL = 8 -- pull the given file from server -- init message function message:init(body) @@ -69,6 +69,11 @@ function message:is_sync() return self:code() == message.CODE_SYNC end +-- is pull message? +function message:is_pull() + return self:code() == message.CODE_PULL +end + -- is clean message? function message:is_clean() return self:code() == message.CODE_CLEAN @@ -144,7 +149,7 @@ function new_disconnect(session_id) }) end --- new diff message +-- new diff message, e.g manifest = {["src/main.c"] = {sha256 = "", mtime = ""}} function new_diff(session_id, manifest) return _new({ code = message.CODE_DIFF, @@ -153,7 +158,7 @@ function new_diff(session_id, manifest) }) end --- new sync message +-- new sync message, e.g. manifest = {modified = {"src/main.c"}, inserted = {}, removed = {}} function new_sync(session_id, manifest) return _new({ code = message.CODE_SYNC, diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index 15f4752b7..f60ee1d3d 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -177,20 +177,30 @@ function remote_build_client:sync() -- archive diff files archive_diff_file, errors = self:_archive_diff_files(diff_files) - if not archive_diff_file then + if not archive_diff_file or not os.isfile(archive_diff_file) then break end -- do sync + local send_ok = false if stream:send_msg(message.new_sync(session_id, diff_files)) and stream:flush() then - local msg = stream:recv_msg() - if msg and msg:success() then - vprint(msg:body()) - ok = true - elseif msg then - errors = msg:errors() + if stream:send_file(archive_diff_file) and stream:flush() then + send_ok = true end end + if not send_ok then + errors = "send files failed" + break + end + + -- sync ok + local msg = stream:recv_msg() + if msg and msg:success() then + vprint(msg:body()) + ok = true + elseif msg then + errors = msg:errors() + end break end if archive_diff_file then diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua index 8a3fd3385..ff15a3d20 100644 --- a/xmake/modules/private/service/remote_build/session.lua +++ b/xmake/modules/private/service/remote_build/session.lua @@ -110,8 +110,8 @@ end function session:sync(respmsg) local body = respmsg:body() local manifest = body.manifest - vprint("%s: %s sync files in %s ..", self, self:sourcedir()) - vprint("%s: %s sync files ok", self) + vprint("%s: sync files in %s ..", self, self:sourcedir()) + vprint("%s: sync files ok", self) end -- clean files |
