changeset 1763:164c6ea53147

fix change_password
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 22 May 2023 19:21:14 -0600
parents 7d2297155ee3
children 527c53b91a50
files src/luan/Luan.java src/luan/host/WebHandler.java src/luan/host/main.luan src/luan/modules/BasicLuan.java src/luan/modules/Luan.luan src/luan/modules/lucene/Lucene.luan src/luan/modules/lucene/LuceneIndex.java
diffstat 7 files changed, 57 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/Luan.java
--- a/src/luan/Luan.java	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/Luan.java	Mon May 22 19:21:14 2023 -0600
@@ -113,6 +113,10 @@
 			clonedLocals(obj).put(key,value);
 	}
 
+	public LuanFunction pairsLocalCloned(Object obj) throws LuanException {
+		return new LuanTable(clonedLocals(obj)).pairs(this);
+	}
+
 	private Map onlyLocals(Object obj) {
 		Map local = (Map)localOnly.get(obj);
 		if( local==null ) {
@@ -133,6 +137,10 @@
 			onlyLocals(obj).put(key,value);
 	}
 
+	public LuanFunction pairsLocalOnly(Object obj) throws LuanException {
+		return new LuanTable(onlyLocals(obj)).pairs(this);
+	}
+
 	public LuanClosure peek() {
 		return peek(1);
 	}
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/host/WebHandler.java
--- a/src/luan/host/WebHandler.java	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/host/WebHandler.java	Mon May 22 19:21:14 2023 -0600
@@ -123,6 +123,22 @@
 		domainHandler.removeHandler(domain);
 	}
 
+	public static void moveTo(String domain,String toDomain,String password) throws LuanException, IOException {
+		toDomain = toDomain.toLowerCase();
+		File fromDir = new File(sitesDir,domain);
+		File toDir = new File(sitesDir,toDomain);
+		synchronized(domain) {
+			if( !fromDir.exists() )
+				throw new LuanException("domain not found");
+			if( toDir.exists() )
+				throw new LuanException("new_domain already exists");
+			callSite(domain,"close_lucene",password);
+			removeHandler(domain);
+			IoUtils.move(fromDir,toDir);
+		}
+		loadHandler(toDomain);
+	}
+
 	public static void loadHandler(String domain) throws LuanException {
 		try {
 			domainHandler.getHandler(domain);
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/host/main.luan
--- a/src/luan/host/main.luan	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/host/main.luan	Mon May 22 19:21:14 2023 -0600
@@ -163,17 +163,8 @@
 end
 
 function fns.change_domain(old_domain,new_domain,password)
-	local old_dir = get_dir(old_domain,password)
-	old_dir or error "domain not found"
-	old_dir = old_dir.parent()
-	type(new_domain)=="string" or error()
-	new_domain = lower(new_domain)
-	local new_dir = sites_dir.child(new_domain)
-	new_dir.exists() and error "new_domain already exists"
-	WebHandler.removeHandler(old_domain)
-	old_dir.move_to(new_dir.to_string())
-	WebHandler.removeHandler(old_domain)
-	WebHandler.loadHandler(new_domain)
+	get_dir(old_domain,password)  -- check password
+	WebHandler.moveTo(old_domain,new_domain,password)
 end
 
 function fns.change_password(domain,old_password,new_password)
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/modules/BasicLuan.java
--- a/src/luan/modules/BasicLuan.java	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/modules/BasicLuan.java	Mon May 22 19:21:14 2023 -0600
@@ -241,6 +241,10 @@
 		luan.setLocalCloned(obj,key,value);
 	}
 
+	public static LuanFunction pairs_local_cloned(Luan luan,Object obj) throws LuanException {
+		return luan.pairsLocalCloned(obj);
+	}
+
 	public static Object get_local_only(Luan luan,Object obj,Object key) {
 		return luan.getLocalOnly(obj,key);
 	}
@@ -249,6 +253,10 @@
 		luan.setLocalOnly(obj,key,value);
 	}
 
+	public static LuanFunction pairs_local_only(Luan luan,Object obj) throws LuanException {
+		return luan.pairsLocalOnly(obj);
+	}
+
 	public static boolean is_immutable(LuanMutable m) {
 		return m.isImmutable();
 	}
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/modules/Luan.luan
--- a/src/luan/modules/Luan.luan	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/modules/Luan.luan	Mon May 22 19:21:14 2023 -0600
@@ -19,6 +19,8 @@
 Luan.load_file = load_file
 Luan.new_error = BasicLuan.new_error
 Luan.pairs = BasicLuan.pairs
+Luan.pairs_local_cloned = BasicLuan.pairs_local_cloned
+Luan.pairs_local_only = BasicLuan.pairs_local_only
 Luan.parse = LuanParser.parse
 Luan.range = BasicLuan.range
 Luan.raw_equal = BasicLuan.raw_equal
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Mon May 22 19:21:14 2023 -0600
@@ -7,6 +7,7 @@
 local set_metatable = Luan.set_metatable or error()
 local get_local_cloned = Luan.get_local_cloned
 local set_local_cloned = Luan.set_local_cloned
+local pairs_local_cloned = Luan.pairs_local_cloned
 local Boot = require "luan:Boot.luan"
 local Html = require "luan:Html.luan"
 local Number = require "luan:Number.luan"
@@ -30,6 +31,7 @@
 local indexes_mt = {
 	__index = get_local_cloned
 	__new_index = set_local_cloned
+	__pairs = pairs_local_cloned
 }
 set_metatable(indexes,indexes_mt)
 
@@ -235,7 +237,18 @@
 		end
 	end
 
+	index.close_down = java_index.close_down
+
 	return index
 end
 
+function Rpc.functions.close_lucene(password)
+	Io.password == password or error "wrong password"
+	logger.info("close_all")
+	for name, index in pairs(indexes) do
+		logger.info("closing "..name)
+		index.close_down()
+	end
+end
+
 return Lucene
diff -r 7d2297155ee3 -r 164c6ea53147 src/luan/modules/lucene/LuceneIndex.java
--- a/src/luan/modules/lucene/LuceneIndex.java	Fri May 19 18:08:46 2023 -0600
+++ b/src/luan/modules/lucene/LuceneIndex.java	Mon May 22 19:21:14 2023 -0600
@@ -416,6 +416,14 @@
 		super.finalize();
 	}
 
+	public void close_down() throws IOException {
+		String key = indexDir.getCanonicalPath();
+		synchronized(indexes) {
+			indexes.remove(key);
+		}
+		close();
+	}
+
 	public void close() throws IOException {
 		closeWriter();
 		reader.close();