comparison src/goodjava/lucene/backup/BackupIndexWriter.java @ 1488:af55cfad6e12

start lucene.backup
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 02 May 2020 15:38:48 -0600
parents
children 22e15cf73040
comparison
equal deleted inserted replaced
1487:044a360c2300 1488:af55cfad6e12
1 package goodjava.lucene.backup;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.List;
6 import java.util.ArrayList;
7 import goodjava.io.IoUtils;
8 import goodjava.lucene.api.LuceneIndexWriter;
9 import goodjava.lucene.logging.LoggingIndexWriter;
10 import goodjava.lucene.logging.LogFile;
11
12
13 public class BackupIndexWriter extends LoggingIndexWriter {
14 private final String name;
15 private final File dir;
16
17 public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,String name) throws IOException {
18 super(indexWriter,logDir);
19 this.name = name;
20 File f = new File(System.getProperty("java.io.tmpdir"));
21 dir = new File(f,"goodjava.lucene/"+name);
22 dir.mkdirs();
23 }
24
25 public synchronized void commit() throws IOException {
26 super.commit();
27 sync();
28 }
29
30 private void sync() throws IOException {
31 for( File f : dir.listFiles() ) {
32 IoUtils.delete(f);
33 }
34 List<LogFile> logs = new ArrayList<LogFile>();
35 for( LogFile log : this.logs ) {
36 File f = new File(dir,log.file.getName());
37 IoUtils.link(log.file,f);
38 logs.add( new LogFile(f) );
39 }
40 }
41
42 }