[
https://issues.apache.org/jira/browse/VFS-172?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Joerg Schaible updated VFS-172:
-------------------------------
Attachment: VFS-172.diff
After some debugging I realized that the SftFileObject will never refresh
itself. Main cause is that - even if it is detached - it keeps it's attribs.
Unfortunately the implementation assumes that it is a real file as long as the
attribs are available. My patch resets now the attribs in doDispatch. This
solves the problem in the following test case (the caching strategy forces a
refresh calling resolveFile):
{code:java}
public void testObjectsAfterMoveOfParentDoNotExistWithSFTP() throws
IOException
{
final FileSystemOptions fsOptions = new FileSystemOptions();
StandardFileSystemManager fsManager = new
StandardFileSystemManager();
fsManager.init();
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());
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());
// resolve forces internal refresh
assertFalse(work.resolveFile("inWork").exists());
assertFalse(inWork.exists());
}
{code}
However, I was not able to run any of the unit tests, they are not found with
M2. So I have no idea if the patch has side effects.
> 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
> Attachments: VFS-172.diff
>
>
> 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.