comparison src/luan/host/main.luan @ 1164:1f9d34a6f308

remove assertions
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 07 Feb 2018 17:36:38 -0700
parents 707a5d874f3e
children 51d1342e25ad
comparison
equal deleted inserted replaced
1163:fef8f0742da9 1164:1f9d34a6f308
1 java() 1 java()
2 local Luan = require "luan:Luan.luan" 2 local Luan = require "luan:Luan.luan"
3 local error = Luan.error 3 local error = Luan.error
4 local assert_string = Luan.assert_string or error() 4 local type = Luan.type or error()
5 local ipairs = Luan.ipairs or error() 5 local ipairs = Luan.ipairs or error()
6 local try = Luan.try or error() 6 local try = Luan.try or error()
7 local Io = require "luan:Io.luan" 7 local Io = require "luan:Io.luan"
8 local print = Io.print or error() 8 local print = Io.print or error()
9 local Rpc = require "luan:Rpc.luan" 9 local Rpc = require "luan:Rpc.luan"
41 41
42 42
43 local fns = Rpc.functions 43 local fns = Rpc.functions
44 44
45 local function get_dir(domain,password) 45 local function get_dir(domain,password)
46 assert_string(domain) 46 type(domain)=="string" or error()
47 assert_string(password) 47 type(password)=="string" or error()
48 domain = lower(domain) 48 domain = lower(domain)
49 local dir = sites_dir.child(domain) 49 local dir = sites_dir.child(domain)
50 if dir.exists() then 50 if dir.exists() then
51 local pwd = dir.child("password").read_text() 51 local pwd = dir.child("password").read_text()
52 if pwd ~= password then 52 if pwd ~= password then
94 94
95 return file_info(site_dir) 95 return file_info(site_dir)
96 end 96 end
97 97
98 function fns.create(domain,password) 98 function fns.create(domain,password)
99 assert_string(domain) 99 type(domain)=="string" or error()
100 assert_string(password) 100 type(password)=="string" or error()
101 domain = lower(domain) 101 domain = lower(domain)
102 local dir = sites_dir.child(domain) 102 local dir = sites_dir.child(domain)
103 dir.exists() and error "already exists" 103 dir.exists() and error "already exists"
104 dir.mkdir() 104 dir.mkdir()
105 dir.child("password").write(password) 105 dir.child("password").write(password)
153 domain = lower(domain) 153 domain = lower(domain)
154 WebHandler.removeHandler(domain) 154 WebHandler.removeHandler(domain)
155 end 155 end
156 156
157 function fns.exists(domain) 157 function fns.exists(domain)
158 assert_string(domain) 158 type(domain)=="string" or error()
159 domain = lower(domain) 159 domain = lower(domain)
160 return sites_dir.child(domain).exists() 160 return sites_dir.child(domain).exists()
161 end 161 end
162 162
163 function fns.change_domain(old_domain,new_domain,password) 163 function fns.change_domain(old_domain,new_domain,password)
164 local old_dir = get_dir(old_domain,password) 164 local old_dir = get_dir(old_domain,password)
165 old_dir or error "domain not found" 165 old_dir or error "domain not found"
166 old_dir = old_dir.parent() 166 old_dir = old_dir.parent()
167 assert_string(new_domain) 167 type(new_domain)=="string" or error()
168 new_domain = lower(new_domain) 168 new_domain = lower(new_domain)
169 local new_dir = sites_dir.child(new_domain) 169 local new_dir = sites_dir.child(new_domain)
170 new_dir.exists() and error "new_domain already exists" 170 new_dir.exists() and error "new_domain already exists"
171 WebHandler.removeHandler(old_domain) 171 WebHandler.removeHandler(old_domain)
172 old_dir.rename_to(new_dir.to_string()) 172 old_dir.rename_to(new_dir.to_string())