Mercurial Hosting > luan
diff src/luan/host/Backup.java @ 1264:d41997776788
fix onClose issues
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 25 Sep 2018 17:03:57 -0600 |
parents | 83c8a5a47f70 |
children | 307e76ccd0d6 |
line wrap: on
line diff
--- a/src/luan/host/Backup.java Mon Sep 24 22:06:25 2018 -0600 +++ b/src/luan/host/Backup.java Tue Sep 25 17:03:57 2018 -0600 @@ -1,9 +1,12 @@ package luan.host; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.Map; +import java.util.List; +import java.util.ArrayList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.lucene.index.SnapshotDeletionPolicy; @@ -64,6 +67,24 @@ luceneInstances = (LuanTable)WebHandler.runLuan( from.getName(), getLucenes, "getLucenes" ); } else { luan = new LuanState(); + luan.onClose = new LuanState.OnClose() { + private final List<Closeable> onClose = new ArrayList<Closeable>(); + + public void onClose(Closeable c) { + onClose.add(c); + } + + public void close() { + for( Closeable c : onClose ) { + try { + c.close(); + } catch(IOException e) { + logger.error(c.toString(),e); + } + } + onClose.clear(); + } + }; WebHandler.initLuan( luan, from.toString(), from.getName() ); PackageLuan.load(luan,"site:/init.luan"); luceneInstances = (LuanTable)luan.eval(getLucenes); @@ -92,7 +113,7 @@ } } if( luan != null ) - luan.close(); + luan.onClose.close(); } public static void backup(File sitesDir,File backupDir) throws IOException {