[ 
https://issues.apache.org/jira/browse/VFS-354?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14876567#comment-14876567
 ] 

Simon Legner commented on VFS-354:
----------------------------------

A smaller unit test case is

{code:java}
        manager.resolveFile("ram://from").createFolder();
        manager.resolveFile("ram://from/file").createFile();
        
manager.resolveFile("ram://from").moveTo(manager.resolveFile("ram://to"));
        assert manager.resolveFile("ram://to/file").exists();
        assert !manager.resolveFile("ram://from/file").exists();
{code}

The problem originates since 
{{org.apache.commons.vfs2.provider.ram.RamFileSystem#rename}} is called with 
{{from}} and {{to}} being directories, but the method implementation can only 
handle files.

> RamFileProvider: moving dir with children fails to move children...
> -------------------------------------------------------------------
>
>                 Key: VFS-354
>                 URL: https://issues.apache.org/jira/browse/VFS-354
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: N/A
>            Reporter: Miroslav Pokorny
>
> Below is a simple program which creates a vfs using a RamFileProvider. Note i 
> have not verified if this works on other providers which are backed by a real 
> filesystem. Im guessing moving on those will work because it would be a 
> disaster for the hose os and it makes no sense that vfs does the moving of 
> individual files.
> Note refreshing the FileObject by fetching them again with resolveFile makes 
> no difference, the "moved" directory remains empty but the file/dir are 
> avaiable by using their absolute paths.
>     /**
>      * @param args
>      */
>     public static void main(String[] args) throws Exception {
>         DefaultFileSystemManager manager = new DefaultFileSystemManager();
>         manager.addProvider("ram", new RamFileProvider());
>         manager.init();
>         final FileObject from = manager.resolveFile("ram://from");
>         from.createFolder();
>         final FileObject move = manager.resolveFile("ram://from/move");
>         move.createFolder();
>         final FileObject fromMoveFile = 
> manager.resolveFile("ram://from/move/file");
>         fromMoveFile.createFile();
>         final FileObject fromMoveSub = 
> manager.resolveFile("ram://from/move/sub");
>         fromMoveSub.createFolder();
>         final FileObject to = manager.resolveFile("ram://to");
>         to.createFolder();
>         final FileObject moveAfter = manager.resolveFile("ram://to/move");
>         System.out.println("target of move " + moveAfter + " exists + " + 
> moveAfter.exists());
>         move.moveTo(moveAfter);
>         System.out.println("move from " + move);
>         System.out.println("\texists " + move.exists());
>         try {
>             System.out.println("\tchildren " + 
> Arrays.toString(move.getChildren()));
>         } catch (final Exception expected) {
>             // ignore expected because folder was moved...
>         }
>         System.out.println("move to " + moveAfter);
>         System.out.println("\texists " + moveAfter.exists());
>         System.out.println("\tchildren " + 
> Arrays.toString(moveAfter.getChildren()));
>         // these tests should print false because they were moved but it 
> prints true...
>         System.out.println("original file " + fromMoveFile + " exists " + 
> fromMoveFile.exists());
>         System.out.println("original sub dir " + fromMoveSub + " exists " + 
> fromMoveSub.exists());
>         // repeating tests with "refreshed" FileObjects problem remains.
>         final FileObject fromMoveFileX = 
> manager.resolveFile("ram://from/move/file");
>         System.out.println("refreshed " + fromMoveFileX + " " + 
> fromMoveFile.exists());
>         final FileObject fromMoveSubX = 
> manager.resolveFile("ram://from/move/sub");
>         System.out.println("refreshed " + fromMoveSubX + " " + 
> fromMoveSubX.exists());
>         // file and dir should have moved but havent.
>         final FileObject toMoveFile = 
> manager.resolveFile("ram://to/move/file");
>         System.out.println("target " + toMoveFile + " " + 
> toMoveFile.exists());
>         final FileObject toMoveSub = manager.resolveFile("ram://to/move/sub");
>         System.out.println("target " + toMoveSub + " " + toMoveSub.exists());
>     }
> prints...
> target of move ram:///to/move exists + false
> move from ram:///from/move
>       exists false
> move to ram:///to/move
>       exists true
>       children []
> original file ram:///from/move/file exists true
> original sub dir ram:///from/move/sub exists true
> refreshed ram:///from/move/file true
> refreshed ram:///from/move/sub true
> target ram:///to/move/file false
> target ram:///to/move/sub false



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to