lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gusenbauer Stefan <>
Subject Re: Can not delete cfs file
Date Sat, 02 Apr 2005 14:32:53 GMT
Gusenbauer Stefan wrote:

> I'm writing a little application and therefore I've implemented unit 
> tests. There i've a method to test my removeindex method, the problem 
> is can't delete the cfs file. When i try to delete it manually it 
> works. But within the tests the method cannot delete this file. I've 
> searched through my code but IndexWriter is always closed. I've read 
> in another java forum that it is possible that are streams on this 
> file open. Is it possible to tell lucene or better to force lucene, 
> that it should close all streams. segments and deleteable i can delete 
> without any problems. I've also tried to force unlock but this makes 
> no changes to the result.
> thanks
> stefan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:
sorry just a few google searches later i found a fine workaround for me
the original is found at 
by Mike 0'Connor. I've made it static and singleton and added a boolean 
return value which is true if the file is really deleted. But it would 
be nice if any of you know why there are open streams or handles on the 
cfs file? Maybe it is a lucene bug?
public class FileDeleter {

    private FileDeleter() {};
    public static boolean deleteFile(File file) {
        if(!file.exists()) {
            return true;
        else {
            return false;
      private static void deleteFile(File file, int tries, int tried) {
        if (!file.delete()) {
          System.gc();  // In case the JVM itself thinks it has a file 
          if (!file.delete()) {
            try {  // Now wait and see if it goes away
            catch (InterruptedException e) {}
            // Potential perma-loop avoided with counter
            // if still there after specified tries, give
            // up, you've got another problem
            if( tried < tries ){

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message