blob: e74c51dbfc8fec960dc1b47fba1e2e37d1313259 [file] [log] [blame]
Index: src/java/org/apache/lucene/index/IndexWriter.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/IndexWriter.java,v
retrieving revision 1.19
diff -w -u -r1.19 IndexWriter.java
--- src/java/org/apache/lucene/index/IndexWriter.java 21 Oct 2003 17:59:16 -0000 1.19
+++ src/java/org/apache/lucene/index/IndexWriter.java 22 Oct 2003 04:11:43 -0000
@@ -300,6 +300,7 @@
int minSegment = segmentInfos.size() - mergeFactor;
mergeSegments(minSegment < 0 ? 0 : minSegment);
}
+ directory.touchFile("segments");
}
/** Merges all segments from an array of indexes into this index.
Index: src/java/org/apache/lucene/store/FSDirectory.java
===================================================================
RCS file: /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/store/FSDirectory.java,v
retrieving revision 1.21
diff -w -u -r1.21 FSDirectory.java
--- src/java/org/apache/lucene/store/FSDirectory.java 25 Sep 2003 21:50:11 -0000 1.21
+++ src/java/org/apache/lucene/store/FSDirectory.java 22 Oct 2003 04:11:43 -0000
@@ -54,11 +54,7 @@
* <http://www.apache.org/>.
*/
-import java.io.IOException;
-import java.io.File;
-import java.io.RandomAccessFile;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.*;
import java.util.Hashtable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -189,23 +185,65 @@
return file.exists();
}
+ static class TimestampFileFilter implements FileFilter
+ {
+ private String name;
+
+ TimestampFileFilter(String name) {
+ this.name = name;
+ }
+
+ public boolean accept(File pathname) {
+ return pathname.getName().startsWith(name + ".");
+ }
+ }
+
+ private static long getLatestTimestamp(File[] files)
+ {
+ long latest = 0;
+ for(int i = 0; i < files.length; i++) {
+ File timestampFile = files[i];
+ String fileName = timestampFile.getName();
+ long timestamp = Long.parseLong(fileName.substring(fileName.lastIndexOf('.')+1));
+ if(timestamp > latest) latest = timestamp;
+ }
+ return latest;
+ }
+
/** Returns the time the named file was last modified. */
public final long fileModified(String name) throws IOException {
- File file = new File(directory, name);
- return file.lastModified();
+ FileFilter filter = new TimestampFileFilter(name);
+ File[] timestamps = directory.listFiles(filter);
+ return getLatestTimestamp(timestamps);
}
/** Returns the time the named file was last modified. */
- public static final long fileModified(File directory, String name)
+ public static final long fileModified(File directory, final String name)
throws IOException {
- File file = new File(directory, name);
- return file.lastModified();
+ FileFilter filter = new TimestampFileFilter(name);
+ File[] timestamps = directory.listFiles(filter);
+ return getLatestTimestamp(timestamps);
}
/** Set the modified time of an existing file to now. */
public void touchFile(String name) throws IOException {
- File file = new File(directory, name);
- file.setLastModified(System.currentTimeMillis());
+ //delete all old timestamps
+ FileFilter filter = new TimestampFileFilter(name);
+ File[] timestamps = directory.listFiles(filter);
+ for(int i = 0; i < timestamps.length; i++) {
+ timestamps[i].delete();
+ }
+ File file = new File(directory, name + "." + System.currentTimeMillis());
+ while(file.exists()) {
+ try {
+ Thread.sleep(0, 1);
+ file.delete();
+ }
+ catch(InterruptedException e) {
+ }
+ file = new File(directory, name + "." + System.currentTimeMillis());
+ }
+ file.createNewFile();
}
/** Returns the length in bytes of a file in the directory. */