# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /home/ondra/netbeans/cdev # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObjTest.java --- masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObjTest.java Base (BASE) +++ masterfs/test/unit/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/FileObjTest.java Locally Modified (Based On LOCAL) @@ -46,6 +46,8 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.util.Arrays; +import java.util.List; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -57,6 +59,7 @@ import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; +import org.openide.util.Utilities; /** * @@ -174,4 +177,49 @@ f.setWritable(true); } } + + public void testFileObjectForBrokenLinkWithGetChildren () throws Exception { + if (!Utilities.isUnix()) { + return; + } + doFileObjectForBrokenLink(true); + } + // public void testFileObjectForBrokenLink() throws Exception { + // if (!Utilities.isUnix()) { + // return; + // } + // doFileObjectForBrokenLink(false); + // } + + private void doFileObjectForBrokenLink (boolean listFirst) throws Exception { + clearWorkDir(); + File wd = new File(getWorkDir(), "wd"); + wd.mkdirs(); + + File original = new File(wd, "original"); +// original.createNewFile(); + for (int i = 0; i < 2; ++i) { + File lockFile = new File(wd, "wlock"); + lockFile.delete(); + FileUtil.toFileObject(wd).refresh(); + ProcessBuilder pb = new ProcessBuilder().directory(wd).command( + new String[]{"ln", "-s", original.getName(), lockFile.getName()}); + pb.start().waitFor(); + final List names = Arrays.asList(lockFile.getParentFile().list()); + assertEquals("One file", 1, names.size()); + // file exists, or at least dir.listFiles lists the file + assertTrue(names.contains(lockFile.getName())); + // java.io.File.exists returns false + assertFalse(lockFile.exists()); + if (listFirst) { + FileObject root = FileUtil.toFileObject(wd); + List arr = Arrays.asList(root.getChildren()); + assertEquals("One files: " + arr, 1, arr.size()); + assertEquals("Has the right name", lockFile.getName(), arr.get(0).getName()); + } + + // and no FileObject is reated for such a file + assertNotNull(FileUtil.toFileObject(lockFile)); + } + } } Index: masterfs/test/unit/src/org/netbeans/modules/masterfs/providers/ProvidedExtensionsTest.java --- masterfs/test/unit/src/org/netbeans/modules/masterfs/providers/ProvidedExtensionsTest.java Base (BASE) +++ masterfs/test/unit/src/org/netbeans/modules/masterfs/providers/ProvidedExtensionsTest.java Locally Modified (Based On LOCAL) @@ -338,7 +338,40 @@ fo.refresh(); assertEquals(1, iListener.implsCreatedExternallyCalls); } + + public void testCreatedDeleteBrokenLinkExternally () throws Exception { + FileObject fo = FileUtil.toFileObject(getWorkDir()); + FileObject[] children = fo.getChildren(); // scan folder + FileObject folder = fo.createFolder("folder"); + iListener.clear(); + assertEquals(0, iListener.implsCreatedExternallyCalls); + File f = new File(FileUtil.toFile(fo), "wlock"); + ProcessBuilder pb = new ProcessBuilder().directory(f.getParentFile()).command(new String[] { "ln", "-s", "doesnotexist", f.getName() }); + pb.start().waitFor(); + assertEquals(0, iListener.implsCreatedExternallyCalls); + fo.refresh(); + assertEquals(1, iListener.implsCreatedExternallyCalls); + iListener.clear(); + f.delete(); + assertEquals(0, iListener.implsDeletedExternallyCalls); + fo.refresh(); + assertEquals(1, iListener.implsDeletedExternallyCalls); + + // let's try once more, now it starts failing + pb = new ProcessBuilder().directory(f.getParentFile()).command(new String[] { "ln", "-s", "doesnotexist", f.getName() }); + pb.start().waitFor(); + iListener.clear(); + assertEquals(0, iListener.implsCreatedExternallyCalls); + fo.refresh(); + assertEquals(1, iListener.implsCreatedExternallyCalls); + iListener.clear(); + f.delete(); + assertEquals(0, iListener.implsDeletedExternallyCalls); + fo.refresh(); + assertEquals(1, iListener.implsDeletedExternallyCalls); + } + public void testDeletedExternally() throws IOException { FileObject fo = FileUtil.toFileObject(getWorkDir()); FileObject file = fo.createData("file");