Cache of SFTP after move completely out of sync.
------------------------------------------------

                 Key: VFS-172
                 URL: https://issues.apache.org/jira/browse/VFS-172
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 1.0
            Reporter: Joerg Schaible
            Priority: Critical


Simple test method. See all the bogus cases at the end:

{code:java}
        public void testObjectsAfterMoveOfParentDoNotExistWithSFTP() throws 
IOException
        {
                final FileSystemOptions fsOptions = new FileSystemOptions();
                final FileSystemManager fsManager = VFS.getManager();
                final FileObject root = fsManager.resolveFile(SFTP_BASE_URL + 
"junit", fsOptions);
                if (!root.exists()) {
                        root.createFolder();
                }

                assertTrue(root.exists());

                final FileObject target = root.resolveFile("target");
                if (!target.exists()) {
                        target.createFolder();
                }

                assertTrue(target.exists());

                final FileObject work = root.resolveFile("work");
                if (!work.exists()) {
                        work.createFolder();
                }

                assertTrue(work.exists());

                FileObject inWork = work.resolveFile("inWork");
                if (!inWork.exists()) {
                        inWork.createFolder();
                }

                assertTrue(inWork.exists());

                final FileObject ready = target.resolveFile("ready-" + 
System.currentTimeMillis());
                assertFalse(ready.exists());

                work.moveTo(ready);
                assertTrue(ready.exists());
                assertFalse(work.exists());

                try {
                        assertFalse(inWork.exists());
                        fail("Thrown " + AssertionFailedError.class.getName() + 
" expected, because of buggy implementation");
                } catch (final AssertionFailedError e) {
                        // <sigh>
                }

                try {
                        inWork.refresh();
                        assertFalse(inWork.exists());
                        fail("Thrown " + AssertionFailedError.class.getName() + 
" expected, because of buggy implementation");
                } catch (final AssertionFailedError e) {
                        // <sigh>
                }

                try {
                        assertFalse(work.resolveFile("inWork").exists());
                        fail("Thrown " + AssertionFailedError.class.getName() + 
" expected, because of buggy implementation");
                } catch (final AssertionFailedError e) {
                        // <sigh>
                }

                try {
                        work.refresh();
                        assertFalse(work.resolveFile("inWork").exists());
                        fail("Thrown " + AssertionFailedError.class.getName() + 
" expected, because of buggy implementation");
                } catch (final AssertionFailedError e) {
                        // <sigh>
                }
                
                // it even possible to write into a file of the non-existing 
folder ...
                FileObject file = inWork.resolveFile("test.txt");
                OutputStream out = file.getContent().getOutputStream();
                out.write("Foo".getBytes());
                try {
                        out.close();
                } catch(IOException e) {
                        // ignore this
                }               
                assertTrue(file.exists());

                // force update of references
                file = null;
                out = null;
                inWork = null;
                System.gc();
                System.gc();
                // ... aaaaahhhh ... something changed
                assertFalse(work.resolveFile("inWork").exists());
        }
{code}

There's not a single possibility to tell VFS that the FileObject is bogus and 
even worse, you can write into non-existing files of a non-existing folder 
without getting an Exception ...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to