Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
609:24b05963ba62 | 610:b4f3dbe1c6e3 |
---|---|
1 -- Hosting | 1 -- Hosting |
2 | 2 |
3 local Io = require "luan:Io" | |
4 local Luan = require "luan:Luan" | 3 local Luan = require "luan:Luan" |
5 local error = Luan.error | 4 local error = Luan.error |
5 local ipairs = Luan.ipairs or error() | |
6 local pairs = Luan.pairs or error() | |
7 local Io = require "luan:Io" | |
8 local print = Io.print or error() | |
9 local Rpc = require "luan:Rpc" | |
10 | |
6 | 11 |
7 local M = {} | 12 local M = {} |
8 | 13 |
9 M.port = 9101 | 14 M.port = 9101 |
10 | 15 |
11 function M.push(domain,password,dir) | 16 function M.push(domain,password,dir) |
12 local f = Io.uri("file:"..dir) | 17 local my_dir = Io.uri("file:"..dir) |
13 f.exists() or error("directory '"..dir.."' not found") | 18 my_dir.exists() or error("directory '"..dir.."' not found") |
14 f.is_directory() or error("'"..dir.."' is not a directory") | 19 my_dir.is_directory() or error("'"..dir.."' is not a directory") |
15 local socket = "socket:" .. domain .. ":" .. M.port | 20 local socket = "socket:" .. domain .. ":" .. M.port |
16 local pc = Io.uri(socket).pickle_client() | 21 local host = Rpc.remote(socket) |
17 local pickle = pc.pickle | 22 local tree = host.get(domain,password) |
18 pc.call(%> | 23 if tree == nil then |
19 local Hosting = require "luan:host/Hosting" | 24 print("creating "..domain) |
20 Hosting.do_push(<%=pickle(domain)%>,<%=pickle(password)%>,<%=pickle(dir)%>) | 25 tree = host.create(domain,password) |
21 <%) | 26 end |
22 pc.close() | 27 |
28 local function process(there_parent,there,here) | |
29 if here.is_file() then | |
30 if there == nil or there.last_modified < here.last_modified() then | |
31 print("copying "..here.to_string()) | |
32 host.copy_file(domain,password,there_parent.path,here.name(),here.read_binary()) | |
33 end | |
34 elseif here.is_directory() then | |
35 if here.name() == "local" then | |
36 return | |
37 end | |
38 if there == nil then | |
39 there = host.mkdir(domain,password,there_parent.path,here.name()) | |
40 end | |
41 for _, here_child in ipairs(here.children()) do | |
42 local name = here_child.name() | |
43 process(there,there.children[name],here_child) | |
44 there.children[name] = nil | |
45 end | |
46 for _, there_child in pairs(there.children) do | |
47 print("deleting "..there_child.name) | |
48 host.delete_unused(domain,password,there_child.path) | |
49 end | |
50 else | |
51 error "not file or dir" | |
52 end | |
53 end | |
54 | |
55 process( nil, tree, my_dir ) | |
56 | |
57 host.remove_handler(domain,password) | |
23 end | 58 end |
24 | 59 |
25 function M.delete(domain,password) | 60 function M.delete(domain,password) |
26 local socket = "socket:" .. domain .. ":" .. M.port | 61 local socket = "socket:" .. domain .. ":" .. M.port |
27 local pc = Io.uri(socket).pickle_client() | 62 local host = Rpc.remote(socket) |
28 local pickle = pc.pickle | 63 host.delete(domain,password) |
29 pc.call(%> | |
30 local Hosting = require "luan:host/Hosting" | |
31 Hosting.do_delete(<%=pickle(domain)%>,<%=pickle(password)%>) | |
32 <%) | |
33 pc.close() | |
34 end | 64 end |
35 | 65 |
36 return M | 66 return M |