comparison src/luan/modules/host/Hosting.luan @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents core/src/luan/modules/host/Hosting.luan@2c41f2aec92f
children e7fb974e0c26
comparison
equal deleted inserted replaced
774:3e30cf310e56 775:1a68fc55a80c
1 -- Hosting
2
3 local Luan = require "luan:Luan.luan"
4 local error = Luan.error
5 local ipairs = Luan.ipairs or error()
6 local pairs = Luan.pairs or error()
7 local set_metatable = Luan.set_metatable or error()
8 local Io = require "luan:Io.luan"
9 local print = Io.print or error()
10 local Rpc = require "luan:Rpc.luan"
11 local String = require "luan:String.luan"
12 local matches = String.matches or error()
13
14
15 local M = {}
16
17
18 function M.push(domain,password,dir)
19 local my_dir = Io.uri("file:"..dir)
20 my_dir.exists() or error("directory '"..dir.."' not found")
21 my_dir.is_directory() or error("'"..dir.."' is not a directory")
22 local host = Rpc.remote(domain)
23 local tree = host.get(domain,password)
24 if tree == nil then
25 print("creating "..domain)
26 tree = host.create(domain,password)
27 end
28
29 local function process(there_parent,there,here)
30 if here.is_file() then
31 if there == nil or there.last_modified < here.last_modified() then
32 print("copying "..here.to_string())
33 host.copy_file(domain,password,there_parent.path,here.name(),here.read_binary())
34 end
35 elseif here.is_directory() then
36 if here.name() == "local" then
37 return
38 end
39 if there == nil then
40 there = host.mkdir(domain,password,there_parent.path,here.name())
41 end
42 for _, here_child in ipairs(here.children()) do
43 local name = here_child.name()
44 if not matches(name,[[^\.]]) then
45 process(there,there.children[name],here_child)
46 there.children[name] = nil
47 end
48 end
49 for _, there_child in pairs(there.children) do
50 if host.delete_unused(domain,password,there_child.path)==true then -- remove ==true later
51 print("deleted "..there_child.name)
52 end
53 end
54 else
55 error "not file or dir"
56 end
57 end
58
59 process( nil, tree, my_dir )
60
61 host.update_handler(domain,password)
62 end
63
64 function M.delete(domain,password)
65 local host = Rpc.remote(domain)
66 host.delete(domain,password)
67 end
68
69 function M.exists(domain)
70 local host = Rpc.remote(domain)
71 return host.exists(domain)
72 end
73
74 function M.change_domain(old_domain,new_domain,password)
75 local host = Rpc.remote(new_domain)
76 return host.change_domain(old_domain,new_domain,password)
77 end
78
79 function M.change_password(domain,old_password,new_password)
80 local host = Rpc.remote(domain)
81 return host.change_password(domain,old_password,new_password)
82 end
83
84 function M.caller(domain)
85 local host = Rpc.remote(domain)
86 local mt = {}
87 function mt.__index(_,key)
88 return function(...)
89 return host.call(domain,key,...)
90 end
91 end
92 local t = {}
93 set_metatable(t,mt)
94 return t
95 end
96
97 return M