Mercurial Hosting > luan
comparison lucene/src/luan/modules/lucene/Lucene.luan @ 761:99356cfde2f0
remove horrible java zip
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 20 Jul 2016 01:52:20 -0600 |
parents | e1dfeddfbc7b |
children | 50f279d3f889 |
comparison
equal
deleted
inserted
replaced
760:2a91bde4e1e1 | 761:99356cfde2f0 |
---|---|
101 return Html.to_string(result) | 101 return Html.to_string(result) |
102 end | 102 end |
103 end | 103 end |
104 | 104 |
105 function index.zip(zip_file) | 105 function index.zip(zip_file) |
106 index.snapshot( function(dir,file_names) | 106 index.snapshot( function(dir_path,file_names) |
107 local t = {} | 107 zip_file.delete() |
108 local zip_path = zip_file.canonical().to_string() | |
109 local dir = uri("file:"..dir_path) | |
110 local dir_name = dir.name() | |
111 local options = {dir=dir.parent()} | |
108 for _, file_name in ipairs(file_names) do | 112 for _, file_name in ipairs(file_names) do |
109 t[#t+1] = dir.."/"..file_name | 113 local cmd = "zip "..zip_path.." "..dir_name.."/"..file_name |
114 Io.uri("os:"..cmd,options).read_text() | |
110 end | 115 end |
111 local base = uri("file:"..dir).parent().to_string() | |
112 zip_file.zip(base,t) | |
113 end ) | 116 end ) |
114 end | 117 end |
115 | 118 |
116 function index.restore(zip_file) | 119 function index.restore(zip_file) |
117 java_index.run_in_lock( function() | 120 java_index.run_in_lock( function() |
118 local lucene_dir = uri("file:"..index.dir) | 121 local lucene_dir = uri("file:"..index.dir) |
119 local before_restore = lucene_dir.parent().child("before_restore.zip") | 122 local before_restore = lucene_dir.parent().child("before_restore.zip") |
120 index.zip(before_restore) | 123 index.zip(before_restore) |
121 java_index.close() | 124 java_index.close() |
122 lucene_dir.delete() | 125 lucene_dir.delete() |
123 zip_file.unzip(lucene_dir.parent().to_string()) | 126 Io.uri("os:unzip "..zip_file.canonical().to_string(),{dir=lucene_dir.parent()}).read_text() |
124 java_index.reopen() | 127 java_index.reopen() |
125 end ) | 128 end ) |
126 end | 129 end |
127 | 130 |
128 local function multi_error() | 131 local function multi_error() |
138 return zip_file | 141 return zip_file |
139 end | 142 end |
140 | 143 |
141 function Rpc.functions.lucene_restore(password,zip_file) | 144 function Rpc.functions.lucene_restore(password,zip_file) |
142 Io.password == password or error "wrong password" | 145 Io.password == password or error "wrong password" |
143 index.restore(zip_file) | 146 local backup_zip = uri("file:"..index.dir).parent().child("backup.zip") |
147 backup_zip.write(zip_file) | |
148 index.restore(backup_zip) | |
144 end | 149 end |
145 | 150 |
146 else | 151 else |
147 Rpc.functions.lucene_backup = multi_error | 152 Rpc.functions.lucene_backup = multi_error |
148 Rpc.functions.lucene_restore = multi_error | 153 Rpc.functions.lucene_restore = multi_error |