[Yanel-dev] virtual file system node does not get deleted
Evaldas Taroza
etaroza at optaros.com
Sat Mar 1 18:00:10 CET 2008
I attached the patch. However, the problem is still there. Although it =
is maybe only related to Windows but still the file should be somehow =
deleted...
Another issue with Yarep is that when I delete a directory then .svn =
stuff is also removed, which causes some synchronization problems =
afterwards. And it does not seem that there could be some way around this.
Evaldas
Michael Wechner wrote:
> Evaldas Taroza wrote:
> =
>> 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 =3D node.getNodes();
>> for (int i=3D0; 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.
> =
> =
> Linux/Unix does not lock files
> =
>> So how to deal with such cases?
> =
> =
> I think the VFS implementation should check after deleting if it has =
> really been deleted and if not, then through an exception itself (for =
> example the message could be: Node could not be deleted, because it =
> might be used by some other application).
> =
> Makes sense?
> =
> Could you provide a patch?
> =
> Thanks
> =
> Michi
> =
>>
>> Evaldas
>>
> =
> =
-- =
+41 79 616 53 76
www.linkedin.com/in/taroza
Optaros - www.optaros.com
-------------- next part --------------
Index: impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemNode.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemNode.java (rev=
ision 32723)
+++ impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemNode.java (wor=
king copy)
@@ -428,25 +428,17 @@
* @see org.wyona.yarep.core.Node#delete()
*/
public void delete() throws RepositoryException {
- deleteRec(this);
- }
- =
- protected void deleteRec(Node node) throws RepositoryException {
- Node[] children =3D node.getNodes();
- for (int i=3D0; i<children.length; i++) {
- deleteRec(children[i]);
- }
- //boolean success =3D getRepository().getMap().delete(new Path(get=
Path()));
try {
- if (getRepository().getMap().isCollection(new Path(getPath()))=
) {
- FileUtils.deleteDirectory(this.contentFile);
+ if (isCollection()) {
+ FileUtils.deleteDirectory(contentFile);
} else {
- this.contentFile.delete();
+ if(!contentFile.delete()){
+ throw new IOException("Unable to delete file. It might=
be used by another application");
+ }
}
- FileUtils.deleteDirectory(this.metaDir);
+ FileUtils.deleteDirectory(metaDir);
} catch (IOException e) {
- throw new RepositoryException("Could not delete node: " + node=
.getPath() + ": " + =
- e.toString(), e);
+ throw new RepositoryException("Could not delete node: " + getP=
ath() + ": " + e.toString(), e);
}
}
=20
More information about the Yanel-development
mailing list