diff src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1499:22e15cf73040

lucene.backup
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 09 May 2020 23:14:13 -0600
parents af55cfad6e12
children e66e3d50b289
line wrap: on
line diff
--- a/src/goodjava/lucene/logging/LoggingIndexWriter.java	Fri May 08 18:07:14 2020 -0600
+++ b/src/goodjava/lucene/logging/LoggingIndexWriter.java	Sat May 09 23:14:13 2020 -0600
@@ -134,12 +134,16 @@
 	}
 
 	private void deleteUnusedFiles() throws IOException {
+		deleteUnusedFiles(logs,index);
+	}
+
+	private static void deleteUnusedFiles(List<LogFile> logs,File index) throws IOException {
 		Set<String> used = new HashSet<String>();
 		used.add( index.getName() );
 		for( LogFile lf : logs ) {
 			used.add( lf.file.getName() );
 		}
-		for( File f : logDir.listFiles() ) {
+		for( File f : index.getParentFile().listFiles() ) {
 			if( !used.contains(f.getName()) ) {
 				IoUtils.deleteRecursively(f);
 			}
@@ -147,6 +151,10 @@
 	}
 
 	private void writeIndex() throws IOException {
+		writeIndex(logs,index);
+	}
+
+	public static void writeIndex(List<LogFile> logs,File index) throws IOException {
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 		DataOutputStream dos = new DataOutputStream(baos);
 		dos.writeInt(version);
@@ -159,8 +167,8 @@
 		RandomAccessFile raf = new RandomAccessFile( index, "rwd" );
 		raf.write( baos.toByteArray() );
 		raf.close();
-		deleteUnusedFiles();
-		logger.info("writeIndex "+logs.toString());
+		deleteUnusedFiles(logs,index);
+		//logger.info("writeIndex "+logs.toString());
 	}
 
 	private void mergeLogs() throws IOException {