public void testFileCaseChange() throws Exception { if (SystemInfo.isFileSystemCaseSensitive) { System.err.println("Ignored: case-insensitive FS required"); return; } File top = createTempDirectory(false); File file = IoTestUtil.createTestFile(top, "file.txt", "test"); File intermediate = new File(top, "_intermediate_"); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile topDir = lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); VirtualFile sourceFile = lfs.refreshAndFindFileByIoFile(file); assertNotNull(sourceFile); String newName = StringUtil.capitalize(file.getName()); FileUtil.rename(file, intermediate); FileUtil.rename(intermediate, new File(top, newName)); topDir.refresh(false, true); assertFalse(((VirtualDirectoryImpl) topDir).allChildrenLoaded()); assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); topDir.getChildren(); newName = newName.toLowerCase(); FileUtil.rename(file, intermediate); FileUtil.rename(intermediate, new File(top, newName)); topDir.refresh(false, true); assertTrue(((VirtualDirectoryImpl) topDir).allChildrenLoaded()); assertTrue(sourceFile.isValid()); assertEquals(newName, sourceFile.getName()); }
public static void doTestPartialRefresh(@NotNull File top) throws IOException { File sub = IoTestUtil.createTestDir(top, "sub"); File file = IoTestUtil.createTestFile(top, "sub.txt"); LocalFileSystem lfs = LocalFileSystem.getInstance(); NewVirtualFile topDir = (NewVirtualFile) lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); NewVirtualFile subDir = (NewVirtualFile) lfs.refreshAndFindFileByIoFile(sub); assertNotNull(subDir); NewVirtualFile subFile = (NewVirtualFile) lfs.refreshAndFindFileByIoFile(file); assertNotNull(subFile); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subDir.isDirty()); assertFalse(subFile.isDirty()); subFile.markDirty(); subDir.markDirty(); assertTrue(topDir.isDirty()); assertTrue(subFile.isDirty()); assertTrue(subDir.isDirty()); topDir.refresh(false, false); assertFalse(subFile.isDirty()); assertTrue(subDir.isDirty()); // should stay unvisited after non-recursive refresh topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile.isDirty()); assertFalse(subDir.isDirty()); }
public void testCopyToPointDir() throws Exception { File top = createTempDirectory(false); File sub = IoTestUtil.createTestDir(top, "sub"); File file = IoTestUtil.createTestFile(top, "file.txt", "hi there"); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile topDir = lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); VirtualFile sourceFile = lfs.refreshAndFindFileByIoFile(file); assertNotNull(sourceFile); VirtualFile parentDir = lfs.refreshAndFindFileByIoFile(sub); assertNotNull(parentDir); assertEquals(2, topDir.getChildren().length); try { sourceFile.copy(this, parentDir, "."); fail("Copying a file into a '.' path should have failed"); } catch (IOException e) { System.out.println(e.getMessage()); } topDir.refresh(false, true); assertTrue(topDir.exists()); assertEquals(2, topDir.getChildren().length); }
public static void doTestInterruptedRefresh(@NotNull File top) throws Exception { File sub = IoTestUtil.createTestDir(top, "sub"); File subSub = IoTestUtil.createTestDir(sub, "sub_sub"); File file1 = IoTestUtil.createTestFile(sub, "sub_file_to_stop_at"); File file2 = IoTestUtil.createTestFile(subSub, "sub_sub_file"); LocalFileSystem lfs = LocalFileSystem.getInstance(); NewVirtualFile topDir = (NewVirtualFile) lfs.refreshAndFindFileByIoFile(top); assertNotNull(topDir); NewVirtualFile subFile1 = (NewVirtualFile) lfs.refreshAndFindFileByIoFile(file1); assertNotNull(subFile1); NewVirtualFile subFile2 = (NewVirtualFile) lfs.refreshAndFindFileByIoFile(file2); assertNotNull(subFile2); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile1.isDirty()); assertFalse(subFile2.isDirty()); try { subFile1.markDirty(); subFile2.markDirty(); RefreshWorker.setCancellingCondition( new Function<VirtualFile, Boolean>() { @Override public Boolean fun(VirtualFile file) { return "sub_file_to_stop_at".equals(file.getName()); } }); topDir.refresh(false, true); // should remain dirty after aborted refresh assertTrue(subFile1.isDirty()); assertTrue(subFile2.isDirty()); RefreshWorker.setCancellingCondition(null); topDir.refresh(false, true); assertFalse(topDir.isDirty()); assertFalse(subFile1.isDirty()); assertFalse(subFile2.isDirty()); } finally { RefreshWorker.setCancellingCondition(null); } }
public void testSymlinkTargetBlink() throws Exception { if (!SystemInfo.areSymLinksSupported) { System.err.println("Ignored: symlinks not supported"); return; } File top = createTempDirectory(true); File target = IoTestUtil.createTestDir(top, "target"); File link = IoTestUtil.createSymLink(target.getPath(), top.getPath() + "/link"); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile vTop = lfs.refreshAndFindFileByIoFile(top); assertNotNull(vTop); assertTrue(vTop.isValid()); VirtualFile vTarget = lfs.refreshAndFindFileByIoFile(target); assertNotNull(vTarget); assertTrue(vTarget.isValid()); VirtualFile vLink = lfs.refreshAndFindFileByIoFile(link); assertNotNull(vLink); assertTrue(vLink.isValid()); assertTrue(vLink.isDirectory()); FileUtil.delete(target); vTop.refresh(false, true); assertFalse(vTarget.isValid()); assertFalse(vLink.isValid()); vLink = lfs.refreshAndFindFileByIoFile(link); assertNotNull(vLink); assertTrue(vLink.isValid()); assertFalse(vLink.isDirectory()); FileUtil.createDirectory(target); vTop.refresh(false, true); assertFalse(vLink.isValid()); vLink = lfs.refreshAndFindFileByIoFile(link); assertNotNull(vLink); assertTrue(vLink.isValid()); assertTrue(vLink.isDirectory()); }