Fixed so that getDirectory(xxx,true) correctly erases the directory

contents, even when the directory has already been accessed in this
JVM.  This was broken by the thread-safety fix.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149610 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2001-10-11 17:21:10 +00:00
parent 4c3e4ce685
commit 6369c5a884
1 changed files with 16 additions and 10 deletions

View File

@ -109,6 +109,8 @@ final public class FSDirectory extends Directory {
if (dir == null) {
dir = new FSDirectory(file, create);
DIRECTORIES.put(file, dir);
} else if (create) {
dir.create();
}
}
synchronized (dir) {
@ -122,20 +124,24 @@ final public class FSDirectory extends Directory {
private FSDirectory(File path, boolean create) throws IOException {
directory = path;
if (!directory.exists() && create)
directory.mkdir();
if (create)
create();
if (!directory.isDirectory())
throw new IOException(path + " not a directory");
}
if (create) { // clear old files
String[] files = directory.list();
for (int i = 0; i < files.length; i++) {
File file = new File(directory, files[i]);
if (!file.delete())
throw new IOException("couldn't delete " + files[i]);
}
private synchronized void create() throws IOException {
if (!directory.exists())
directory.mkdir();
String[] files = directory.list(); // clear old files
for (int i = 0; i < files.length; i++) {
File file = new File(directory, files[i]);
if (!file.delete())
throw new IOException("couldn't delete " + files[i]);
}
}
/** Returns an array of strings, one for each file in the directory. */