You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Gusenbauer Stefan <gu...@eduhi.at> on 2005/04/02 16:13:06 UTC
Can not delete cfs file
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Can not delete cfs file
Posted by Gusenbauer Stefan <gu...@eduhi.at>.
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: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
sorry just a few google searches later i found a fine workaround for me
the original is found at
http://forum.java.sun.com/thread.jspa?threadID=158689&messageID=2033384
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?
thanks
Stefan
public class FileDeleter {
private FileDeleter() {};
public static boolean deleteFile(File file) {
deleteFile(file,10,0);
if(!file.exists()) {
return true;
}//ifs
else {
return false;
}//else
}
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
handle
if (!file.delete()) {
try { // Now wait and see if it goes away
Thread.sleep(200);
}//try
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 ){
deleteFile(file,tries,tried++);
}//if
}//if
}//if
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Can not delete cfs file
Posted by Gusenbauer Stefan <gu...@eduhi.at>.
Gusenbauer Stefan wrote:
>Erik Hatcher wrote:
>
>
>
>>On Apr 3, 2005, at 3:33 PM, Gusenbauer Stefan wrote:
>>
>>
>>
>>>Sorry for beeing late!
>>>Only the test code wouldn't be very useful for understanding because
>>>there are a lot of dependencies in the other code. I can explain what
>>>I do: I open an IndexWrite close it then open an IndexReader close it
>>>and open an IndexWriter then close it. Then i try to delete the files
>>>from the index and only the cfs file i cannot delete. I try to get
>>>out the code which is involved later on. I get no failure message
>>>only the
>>>that the fail could not be removed.
>>>
>>>
>>This is on Windows, I presume?
>>
>> Erik
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>>
>>
>>
>Yes, I think it is a java with windows problem because since a use call
>System.gc before deleting the file the streams are released.
>Stefan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
>
>
I found the bug, i simply didn't close the indexreader in the testcase
before. Shame on me that I've assumed that lucene had a bug!
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Can not delete cfs file
Posted by Gusenbauer Stefan <gu...@eduhi.at>.
Erik Hatcher wrote:
>
> On Apr 3, 2005, at 3:33 PM, Gusenbauer Stefan wrote:
>
>> Sorry for beeing late!
>> Only the test code wouldn't be very useful for understanding because
>> there are a lot of dependencies in the other code. I can explain what
>> I do: I open an IndexWrite close it then open an IndexReader close it
>> and open an IndexWriter then close it. Then i try to delete the files
>> from the index and only the cfs file i cannot delete. I try to get
>> out the code which is involved later on. I get no failure message
>> only the
>> that the fail could not be removed.
>
>
> This is on Windows, I presume?
>
> Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
Yes, I think it is a java with windows problem because since a use call
System.gc before deleting the file the streams are released.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Can not delete cfs file
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Apr 3, 2005, at 3:33 PM, Gusenbauer Stefan wrote:
> Sorry for beeing late!
> Only the test code wouldn't be very useful for understanding because
> there are a lot of dependencies in the other code. I can explain what
> I do: I open an IndexWrite close it then open an IndexReader close it
> and open an IndexWriter then close it. Then i try to delete the files
> from the index and only the cfs file i cannot delete. I try to get out
> the code which is involved later on. I get no failure message only the
> that the fail could not be removed.
This is on Windows, I presume?
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Can not delete cfs file
Posted by Gusenbauer Stefan <gu...@eduhi.at>.
Erik Hatcher wrote:
> Could you provide your test case code as well as the full stack trace
> of the error you're receiving?
>
> Erik
>
> On Apr 2, 2005, at 9:13 AM, 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: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
Sorry for beeing late!
Only the test code wouldn't be very useful for understanding because
there are a lot of dependencies in the other code. I can explain what I
do: I open an IndexWrite close it then open an IndexReader close it and
open an IndexWriter then close it. Then i try to delete the files from
the index and only the cfs file i cannot delete. I try to get out the
code which is involved later on. I get no failure message only the
that the fail could not be removed.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Can not delete cfs file
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Could you provide your test case code as well as the full stack trace
of the error you're receiving?
Erik
On Apr 2, 2005, at 9:13 AM, 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: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org