Mercurial Hosting > luan
diff core/src/luan/modules/host/Hosting.luan @ 610:b4f3dbe1c6e3
add Rpc and change Hosting to use Rpc
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Dec 2015 00:13:13 -0700 |
parents | 92c3d22745b8 |
children | abc3198c86dd |
line wrap: on
line diff
--- a/core/src/luan/modules/host/Hosting.luan Wed Dec 09 18:12:16 2015 -0700 +++ b/core/src/luan/modules/host/Hosting.luan Fri Dec 11 00:13:13 2015 -0700 @@ -1,36 +1,66 @@ -- Hosting -local Io = require "luan:Io" local Luan = require "luan:Luan" local error = Luan.error +local ipairs = Luan.ipairs or error() +local pairs = Luan.pairs or error() +local Io = require "luan:Io" +local print = Io.print or error() +local Rpc = require "luan:Rpc" + local M = {} M.port = 9101 function M.push(domain,password,dir) - local f = Io.uri("file:"..dir) - f.exists() or error("directory '"..dir.."' not found") - f.is_directory() or error("'"..dir.."' is not a directory") + local my_dir = Io.uri("file:"..dir) + my_dir.exists() or error("directory '"..dir.."' not found") + my_dir.is_directory() or error("'"..dir.."' is not a directory") local socket = "socket:" .. domain .. ":" .. M.port - local pc = Io.uri(socket).pickle_client() - local pickle = pc.pickle - pc.call(%> - local Hosting = require "luan:host/Hosting" - Hosting.do_push(<%=pickle(domain)%>,<%=pickle(password)%>,<%=pickle(dir)%>) - <%) - pc.close() + local host = Rpc.remote(socket) + local tree = host.get(domain,password) + if tree == nil then + print("creating "..domain) + tree = host.create(domain,password) + end + + local function process(there_parent,there,here) + if here.is_file() then + if there == nil or there.last_modified < here.last_modified() then + print("copying "..here.to_string()) + host.copy_file(domain,password,there_parent.path,here.name(),here.read_binary()) + end + elseif here.is_directory() then + if here.name() == "local" then + return + end + if there == nil then + there = host.mkdir(domain,password,there_parent.path,here.name()) + end + for _, here_child in ipairs(here.children()) do + local name = here_child.name() + process(there,there.children[name],here_child) + there.children[name] = nil + end + for _, there_child in pairs(there.children) do + print("deleting "..there_child.name) + host.delete_unused(domain,password,there_child.path) + end + else + error "not file or dir" + end + end + + process( nil, tree, my_dir ) + + host.remove_handler(domain,password) end function M.delete(domain,password) local socket = "socket:" .. domain .. ":" .. M.port - local pc = Io.uri(socket).pickle_client() - local pickle = pc.pickle - pc.call(%> - local Hosting = require "luan:host/Hosting" - Hosting.do_delete(<%=pickle(domain)%>,<%=pickle(password)%>) - <%) - pc.close() + local host = Rpc.remote(socket) + host.delete(domain,password) end return M