Mercurial Hosting > luan
changeset 749:85f5444fb7d4
add rcp lucene backup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 15 Jul 2016 01:18:01 -0600 |
parents | de2418d11786 |
children | f172f1dff4b6 |
files | core/src/luan/modules/IoLuan.java core/src/luan/modules/host/backup.luan lucene/src/luan/modules/lucene/Lucene.luan |
diffstat | 3 files changed, 45 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
diff -r de2418d11786 -r 85f5444fb7d4 core/src/luan/modules/IoLuan.java --- a/core/src/luan/modules/IoLuan.java Thu Jul 14 21:09:55 2016 -0600 +++ b/core/src/luan/modules/IoLuan.java Fri Jul 15 01:18:01 2016 -0600 @@ -542,6 +542,12 @@ return new LuanFile(luan,file.getCanonicalFile()).table(); } + public LuanTable create_temp_file(LuanState luan,String prefix,String suffix) throws LuanException, IOException { + File tmp = File.createTempFile(prefix,suffix,file); + tmp.deleteOnExit(); + return new LuanFile(luan,tmp).table(); + } + @Override public LuanTable table() { LuanTable tbl = super.table(); try { @@ -581,6 +587,9 @@ tbl.rawPut( "canonical", new LuanJavaFunction( LuanFile.class.getMethod( "canonical", LuanState.class ), this ) ); + tbl.rawPut( "create_temp_file", new LuanJavaFunction( + LuanFile.class.getMethod( "create_temp_file", LuanState.class, String.class, String.class ), this + ) ); } catch(NoSuchMethodException e) { throw new RuntimeException(e); }
diff -r de2418d11786 -r 85f5444fb7d4 core/src/luan/modules/host/backup.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/src/luan/modules/host/backup.luan Fri Jul 15 01:18:01 2016 -0600 @@ -0,0 +1,18 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local print = Io.print or error() +local uri = Io.uri or error() +local Hosting = require "luan:host/Hosting.luan" + +if #{...} ~= 2 then + Io.stderr.write "usage: luan luan:host/update.luan domain password\n" + return +end + +local domain, password = ... + +local zip = Hosting.caller(domain).lucene_backup(password) +uri("file:backup.zip").write(zip) + +print("backed up lucene from "..domain.." to backup.zip")
diff -r de2418d11786 -r 85f5444fb7d4 lucene/src/luan/modules/lucene/Lucene.luan --- 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