diff lucene/src/luan/modules/lucene/Lucene.luan @ 749:85f5444fb7d4

add rcp lucene backup
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 15 Jul 2016 01:18:01 -0600
parents de2418d11786
children 5e3970ccd86a
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Thu Jul 14 21:09:55 2016 -0600
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Fri Jul 15 01:18:01 2016 -0600
@@ -8,6 +8,8 @@
 local uri = Io.uri or error()
 local String = require "luan:String.luan"
 local matches = String.matches or error()
+local Rpc = require "luan:Rpc.luan"
+local Hosting = require "luan:host/Hosting.luan"
 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
 local NumberFieldParser = require "java:luan.modules.lucene.queryparser.NumberFieldParser"
 local StringFieldParser = require "java:luan.modules.lucene.queryparser.StringFieldParser"
@@ -102,17 +104,31 @@
 	end
 
 	function index.zip(zip_file)
-		matches(zip_file,[[\.zip$]]) or error("file "..zip_file.." doesn't end with '.zip'")
 		index.snapshot( function(dir,file_names)
 			local t = {}
 			for _, file_name in ipairs(file_names) do
 				t[#t+1] = dir.."/"..file_name
 			end
 			local base = uri("file:"..dir).parent().to_string()
-			uri(zip_file).zip(base,t)
+			zip_file.zip(base,t)
 		end )
 	end
 
+	if Rpc.functions.backup == nil then
+		function Rpc.functions.lucene_backup(password)
+			if Hosting.password ~= nil and Hosting.password ~= password then
+				error "wrong password"
+			end
+			local zip_file = uri("file:"..index.dir).parent().child("backup.zip")
+			index.zip(zip_file)
+			return zip_file
+		end
+	else
+		function Rpc.functions.lucene_backup()
+			error "multiple lucene instance"
+		end
+	end
+
 	return index
 end