public void testGetAttributesConvertsToAbsolute() throws Exception { PersistentFS fs = PersistentFS.getInstance(); LocalFileSystem lfs = LocalFileSystem.getInstance(); NewVirtualFile fakeRoot = fs.findRoot("", lfs); assertNotNull(fakeRoot); File userDir = new File(System.getProperty("user.dir")); File[] files = userDir.listFiles(); File fileToQuery; if (files != null && files.length != 0) { fileToQuery = files[0]; } else if (userDir.isDirectory()) { fileToQuery = FileUtil.createTempFile(userDir, getTestName(false), "", true); myFilesToDelete.add(fileToQuery); } else { // can't test return; } FileAttributes attributes = lfs.getAttributes(new FakeVirtualFile(fakeRoot, fileToQuery.getName())); assertNull(attributes); attributes = lfs.getAttributes(new FakeVirtualFile(fakeRoot, "windows")); assertNull(attributes); attributes = lfs.getAttributes(new FakeVirtualFile(fakeRoot, "usr")); assertNull(attributes); attributes = lfs.getAttributes(new FakeVirtualFile(fakeRoot, "Users")); assertNull(attributes); }
private void queueUnresolvedFilesSinceLastRestart() { PersistentFS fs = PersistentFS.getInstance(); int maxId = FSRecords.getMaxId(); TIntArrayList list = new TIntArrayList(); for (int id = fileIsResolved.nextClearBit(1); id >= 0 && id < maxId; id = fileIsResolved.nextClearBit(id + 1)) { int nextSetBit = fileIsResolved.nextSetBit(id); int endOfRun = Math.min(maxId, nextSetBit == -1 ? maxId : nextSetBit); do { VirtualFile virtualFile = fs.findFileById(id); if (queueIfNeeded(virtualFile, myProject)) { list.add(id); } else { fileIsResolved.set(id); } } while (++id < endOfRun); } log("Initially added to resolve " + toVfString(list.toNativeArray())); }
@NotNull private static List<VirtualFile> toVf(@NotNull int[] ids) { List<VirtualFile> res = new ArrayList<VirtualFile>(); for (int id : ids) { VirtualFile file = PersistentFS.getInstance().findFileById(id); if (file != null) { res.add(file); } } return res; }
public void testFileLength() throws Exception { File file = FileUtil.createTempFile("test", "txt"); FileUtil.writeToFile(file, "hello"); VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); assertNotNull(virtualFile); String s = VfsUtilCore.loadText(virtualFile); assertEquals("hello", s); assertEquals(5, virtualFile.getLength()); FileUtil.writeToFile(file, "new content"); ((PersistentFSImpl) PersistentFS.getInstance()).cleanPersistedContents(); s = VfsUtilCore.loadText(virtualFile); assertEquals("new content", s); assertEquals(11, virtualFile.getLength()); }
@Override @NotNull public Iterable<VirtualFile> iterInDbChildren() { if (!ourPersistence.wereChildrenAccessed(this)) { return Collections.emptyList(); } if (!ourPersistence.areChildrenLoaded(this)) { final String[] names = ourPersistence.listPersisted(this); final NewVirtualFileSystem delegate = PersistentFS.replaceWithNativeFS(getFileSystem()); for (String name : names) { findChild(name, false, false, delegate); } } return getCachedChildren(); }
@Override public boolean process(IndexTree.Unit unit) { VirtualFile file = PersistentFS.getInstance().findFileById(unit.myFileId); if (file == null) { return true; } boolean process = isInSourceMode ? myProjectIndex.isInSourceContent(file) : myProjectIndex.isInLibraryClasses(file); if (process) { myHierarchyService.processUnit(unit); myProcessedSet.set(unit.myFileId); } return true; }
@NotNull public VirtualFileSystemEntry createChild( @NotNull String name, int id, @NotNull NewVirtualFileSystem delegate) { VirtualFileSystemEntry child; final int attributes = ourPersistence.getFileAttributes(id); if (PersistentFS.isDirectory(attributes)) { child = new VirtualDirectoryImpl(name, this, delegate, id, attributes); } else { child = new VirtualFileImpl(name, this, id, attributes); //noinspection TestOnlyProblems assertAccessInTests(child, delegate); } if (delegate.markNewFilesAsDirty()) { child.markDirty(); } return child; }
private static void cleanPersistedVFSContent() { ((PersistentFSImpl) PersistentFS.getInstance()).cleanPersistedContents(); }