[Yanel-dev] virtual file system node does not get deleted
Evaldas Taroza
etaroza at optaros.com
Sat Mar 1 15:37:26 CET 2008
Hi,
I use VirtualFileSystemRepository in the project. I have a Node which I
want to delete, so I call:
node.delete();
but it is not deleted... I looked into the implementation, and for me it
seems to have some bugs (although in my case it should have worked)
LINE 430:
------
public void delete() throws RepositoryException {
deleteRec(this);
}
protected void deleteRec(Node node) throws RepositoryException {
Node[] children = node.getNodes();
for (int i=0; i<children.length; i++) {
deleteRec(children[i]);
}
try {
if (getRepository().getMap().isCollection(new Path(getPath()))) {
FileUtils.deleteDirectory(this.contentFile);
} else {
this.contentFile.delete();
}
FileUtils.deleteDirectory(this.metaDir);
} catch (IOException e) {
throw new RepositoryException("Could not delete node: " +
node.getPath() + ": " + e.toString(), e);
}
}
----
So the problems I see in this code is that the deleteRec recursively is
deleting the same file - this.contentFile. Everywhere this method should
refer to "node":
node.getPath()
node.contentFile.delete()
node.metaDir
However, I was deleting one file only, so recursion is of the depth 0
and therefore this.contentFile.delete() should have worked. But
apparently the file is still there, and no exceptions thrown. Indeed, if
you look at
http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#delete()
it is never throwing a IOException on failure.
The file which is not deleted is most likely used by the browser, and
therefore is locked. So how to deal with such cases?
Evaldas
--
+41 79 616 53 76
www.linkedin.com/in/taroza
Optaros - www.optaros.com
More information about the Yanel-development
mailing list