changeset 1596:a9ff30fb5d89

add Hosting.push_file
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Mar 2021 20:10:44 -0600
parents e4deb32bd233
children cd2a0c41b23f
files src/luan/LuanException.java src/luan/modules/Rpc.luan src/luan/modules/host/Hosting.luan
diffstat 3 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/LuanException.java	Sun Mar 21 16:13:05 2021 -0600
+++ b/src/luan/LuanException.java	Fri Mar 26 20:10:44 2021 -0600
@@ -13,6 +13,7 @@
 	private LuanTable table;
 	private Map extra = new HashMap();
 	private boolean immutable = false;
+	public boolean showCause = true;
 
 	public LuanException(String msg,Throwable cause) {
 		super(msg,cause);
@@ -126,7 +127,7 @@
 	public String getLuanStackTraceString() {
 		StringBuilder sb = luanStackTrace();
 		Throwable cause = getCause();
-		if( cause != null )
+		if( showCause && cause != null )
 			sb.append( "\nCaused by: " ).append( getJavaStackTraceString(cause) );
 		return sb.toString();
 	}
--- a/src/luan/modules/Rpc.luan	Sun Mar 21 16:13:05 2021 -0600
+++ b/src/luan/modules/Rpc.luan	Fri Mar 26 20:10:44 2021 -0600
@@ -175,7 +175,12 @@
 	if Rpc.cipher_suites == nil then
 		socket = Socket.new(domain,Rpc.port)
 	else
-		socket = IoUtils.getSSLSocketFactory().createSocket(domain,Rpc.port)
+		try
+			socket = IoUtils.getSSLSocketFactory().createSocket(domain,Rpc.port)
+		catch e
+			e.java.showCause = false
+			e.throw()
+		end
 		socket.setEnabledCipherSuites(Rpc.cipher_suites)
 	end
 	local call = rpc_caller(socket)
--- a/src/luan/modules/host/Hosting.luan	Sun Mar 21 16:13:05 2021 -0600
+++ b/src/luan/modules/host/Hosting.luan	Fri Mar 26 20:10:44 2021 -0600
@@ -3,11 +3,14 @@
 local ipairs = Luan.ipairs or error()
 local pairs = Luan.pairs or error()
 local set_metatable = Luan.set_metatable or error()
+local stringify = Luan.stringify or error()
 local Io = require "luan:Io.luan"
 local print = Io.print or error()
 local Rpc = require "luan:Rpc.luan"
 local String = require "luan:String.luan"
 local matches = String.matches or error()
+local substring = String.sub or error()
+local split = String.split or error()
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "Hosting"
 
@@ -61,6 +64,28 @@
 	host.close()
 end
 
+function Hosting.push_file(domain,password,dir,file)
+	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 my_file = Io.uri("file:"..file)
+	my_file.exists() or error("file '"..file.."' not found")
+	my_file.is_file() or error("'"..file.."' is not a file")
+	local my_file_string = my_file.to_string()
+	local my_dir_string = my_dir.to_string().."/"
+	matches( my_file_string, [[^\Q]]..my_dir_string..[[\E]] ) or error "file must be in dir"
+	my_file_string = substring(my_file_string,#my_dir_string+1)
+	local path = {split( my_file_string, "/" )}
+	path[#path] = nil
+	local host = Rpc.remote(domain)
+	local there = host.get(domain,password)
+	there~=nil or error "site not created"
+	for _, s in ipairs(path) do
+		there = there.children[s] or error("'"..s.."' not found on remote")
+	end
+	host.copy_file(domain,password,there.path,my_file.name(),my_file.read_binary())
+end
+
 function Hosting.delete(domain,password)
 	local host = Rpc.remote(domain)
 	host.delete(domain,password)