[Yanel-dev] virtual file system node does not get deleted

Josias Thöny josias.thoeny at wyona.com
Mon Mar 3 08:52:29 CET 2008


Evaldas Taroza wrote:
> 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...

Do you think the file is still accessed by Yanel itself? Or maybe by 
some other application?
If it's accessed by Yanel, maybe we forgot to close a stream somewhere.

josias

> 
> 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 = 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.
>>
>>
>> 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
>>>
>>
>>
> 
> 
> 
> ------------------------------------------------------------------------
> 
> Index: impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemNode.java
> ===================================================================
> --- impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemNode.java	(revision 32723)
> +++ impl/java/org/wyona/yarep/impl/repo/vfs/VirtualFileSystemNode.java	(working 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 = node.getNodes();
> -        for (int i=0; i<children.length; i++) {
> -            deleteRec(children[i]);
> -        }
> -        //boolean success = getRepository().getMap().delete(new Path(getPath()));
>          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: " + getPath() + ": " +  e.toString(), e);
>          }
>      }
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development


-- 
Josias Thöny
Wyona - Open Source Content Management
http://www.wyona.com


More information about the Yanel-development mailing list