[Yanel-dev] virtual file system node does not get deleted
Michael Wechner
michael.wechner at wyona.com
Sat Mar 1 19:38:08 CET 2008
Evaldas Taroza wrote:
> I attached the patch.
thanks, will review it asap
> However, the problem is still there.
how so?
> Although it is maybe only related to Windows but still the file should
> be somehow deleted...
I guess it should not be deleted, but an exception should be thrown, right?
>
> 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.
I think we can make this configurable within the VFS repo config
(similar to the ignore of collection listings)
WDYT?
Cheers
Michi
>
> 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
>
>
--
Michael Wechner
Wyona - Open Source Content Management - Yanel, Yulup
http://www.wyona.com
michael.wechner at wyona.com, michi at apache.org
+41 44 272 91 61
More information about the Yanel-development
mailing list