@NotNull public static List<VirtualFile> markDirty(boolean recursive, boolean reloadChildren, @NotNull VirtualFile... files) { List<VirtualFile> list = ContainerUtil.filter(Condition.NOT_NULL, files); if (list.isEmpty()) { return Collections.emptyList(); } for (VirtualFile file : list) { if (reloadChildren) { file.getChildren(); } if (file instanceof NewVirtualFile) { if (recursive) { ((NewVirtualFile)file).markDirtyRecursively(); } else { ((NewVirtualFile)file).markDirty(); } } } return list; }
boolean isFileIgnored(@NotNull VirtualFile file) { if (myVfsEventNesting != 0 || !(file instanceof NewVirtualFile)) { return isFileIgnoredNoCache(file); } int id = ((NewVirtualFile)file).getId(); if (id < 0) { return isFileIgnoredNoCache(file); } ConcurrentBitSet checkedIds = myCheckedIds; if (checkedIds.get(id)) { return myIgnoredIds.containsKey(id); } boolean result = isFileIgnoredNoCache(file); if (result) { myIgnoredIds.put(id, Boolean.TRUE); } else { myIgnoredIds.remove(id); } checkedIds.set(id); return result; }
public void scan() { NewVirtualFile root = myRefreshQueue.pullFirst().first; boolean rootDirty = root.isDirty(); debug(LOG, "root=%s dirty=%b", root, rootDirty); if (!rootDirty) return; NewVirtualFileSystem fs = root.getFileSystem(); FileAttributes rootAttributes = fs.getAttributes(root); if (rootAttributes == null) { scheduleDeletion(root); root.markClean(); return; } else if (rootAttributes.isDirectory()) { fs = PersistentFS.replaceWithNativeFS(fs); } myRefreshQueue.addLast(pair(root, rootAttributes)); try { processQueue(fs, PersistentFS.getInstance()); } catch (RefreshCancelledException e) { LOG.debug("refresh cancelled"); } }
public void markSuspiciousFilesDirty(List<VirtualFile> files) { storeRefreshStatusToFiles(); if (myWatcher.isOperational()) { for (String root : myWatcher.getManualWatchRoots()) { final VirtualFile suspiciousRoot = findFileByPathIfCached(root); if (suspiciousRoot != null) { ((NewVirtualFile)suspiciousRoot).markDirtyRecursively(); } } } else { for (VirtualFile file : files) { if (file.getFileSystem() == this) { ((NewVirtualFile)file).markDirtyRecursively(); } } } }
@Override public void refreshWithoutFileWatcher(final boolean asynchronous) { Runnable heavyRefresh = new Runnable() { @Override public void run() { for (VirtualFile root : myManagingFS.getRoots(LocalFileSystemImpl.this)) { ((NewVirtualFile)root).markDirtyRecursively(); } refresh(asynchronous); } }; if (asynchronous && myWatcher.isOperational()) { RefreshQueue.getInstance().refresh(true, true, heavyRefresh, myManagingFS.getRoots(this)); } else { heavyRefresh.run(); } }
@Override public void refreshOpenFiles() { List<VirtualFile> files = ContainerUtil.newArrayList(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) { if (file instanceof NewVirtualFile) { files.add(file); } } } if (!files.isEmpty()) { // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish RefreshQueue.getInstance().refresh(false, false, null, files); } }
@Nullable public static String getFrameworkIdOfBuildFile(VirtualFile file) { if (file instanceof NewVirtualFile) { final DataInputStream is = FRAMEWORK_FILE_ATTRIBUTE.readAttribute(file); if (is != null) { try { try { if (is.available() == 0) { return null; } return IOUtil.readString(is); } finally { is.close(); } } catch (IOException e) { LOG.error(file.getPath(), e); } } return ""; } return file.getUserData(FRAMEWORK_FILE_MARKER); }
private static void forceBuildFile(VirtualFile file, @Nullable String value) { if (file instanceof NewVirtualFile) { final DataOutputStream os = FRAMEWORK_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize(value), os); } finally { os.close(); } } catch (IOException e) { LOG.error(e); } } else { file.putUserData(FRAMEWORK_FILE_MARKER, value); } }
public void testFindRootPerformance() throws IOException { File tempJar = IoTestUtil.createTestJar(); final VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); final JarFileSystem fs = JarFileSystem.getInstance(); final String path = jar.getPath() + "!/"; final NewVirtualFile root = ManagingFS.getInstance().findRoot(path, fs); PlatformTestUtil.startPerformanceTest("find root is slow", 5000, new ThrowableRunnable() { @Override public void run() throws Throwable { JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, false, new Processor<Object>() { @Override public boolean process(Object o) { for (int i = 0; i < 20000; i++) { NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fs); assertNotNull(rootJar); assertSame(root, rootJar); } return true; } }); } }).assertTiming(); }
private void addFileToDelete(VirtualFile file) { if (file.isDirectory() && file instanceof NewVirtualFile && !isDirectoryVersioningSupported()) { for (VirtualFile child : ((NewVirtualFile)file).getCachedChildren()) { addFileToDelete(child); } } else { final VcsDeleteType type = needConfirmDeletion(file); final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOnDeleted(new File(file.getPath()), file.isDirectory()); if (type == VcsDeleteType.CONFIRM) { myDeletedFiles.add(filePath); } else if (type == VcsDeleteType.SILENT) { myDeletedWithoutConfirmFiles.add(filePath); } } }
@Override public void actionPerformed(AnActionEvent e) { final Project project = getEventProject(e); final VirtualFile[] files = getFiles(e); if (project == null || files == null || files.length == 0) return; ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (VirtualFile file : files) { if (file instanceof NewVirtualFile) { ((NewVirtualFile)file).markDirtyRecursively(); } } } }); RefreshQueue.getInstance().refresh(true, true, new Runnable() { @Override public void run() { postRefresh(project, files); } }, files); }
public boolean processFile(NewVirtualFile file) { if (file.isDirectory() || file.is(VFileProperty.SPECIAL)) { return true; } try { DataInputStream stream = FSRecords.readContent(file.getId()); if (stream == null) return true; byte[] bytes = FileUtil.loadBytes(stream); totalSize.addAndGet(bytes.length); count.incrementAndGet(); ProgressManager.getInstance().getProgressIndicator().setText(file.getPresentableUrl()); } catch (IOException e) { LOG.error(e); } return true; }
private static boolean isAntFileOld(VirtualFile file) { if (file instanceof NewVirtualFile) { final DataInputStream is = ourAttribute.readAttribute(file); if (is != null) { try { try { return is.readBoolean(); } finally { is.close(); } } catch (IOException e) { LOG.error(e); } } return false; } return Boolean.TRUE.equals(file.getUserData(ourAntFileMarker)); }
@Override public boolean visitFile(VirtualFile file) { file.putUserData(MODIFICATION_DATE_KEY, null); if(file instanceof NewVirtualFile) { final DataOutputStream os = MODIFICATION_STAMP_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize("0"), os); } finally { os.close(); } } catch(IOException e) { // Ignore it but we might need to throw an exception String message = e.getMessage(); } } return recursive; }
public static void setModificationStamp(VirtualFile file) { // Store it in memory first if(file != null) { file.putUserData(Util.MODIFICATION_DATE_KEY, file.getTimeStamp()); if(file instanceof NewVirtualFile) { final DataOutputStream os = MODIFICATION_STAMP_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize(file.getTimeStamp() + ""), os); } finally { os.close(); } } catch(IOException e) { // Ignore it but we might need to throw an exception String message = e.getMessage(); } } } }
@NotNull public static List<VirtualFile> markDirty(boolean recursive, boolean reloadChildren, VirtualFile... files) { List<VirtualFile> list = ContainerUtil.filter(Condition.NOT_NULL, files); if (list.isEmpty()) { return Collections.emptyList(); } for (VirtualFile file : list) { if (reloadChildren) { file.getChildren(); } if (file instanceof NewVirtualFile) { if (recursive) { ((NewVirtualFile)file).markDirtyRecursively(); } else { ((NewVirtualFile)file).markDirty(); } } } return list; }
public static void refreshOpenFiles() { List<VirtualFile> files = ContainerUtil.newArrayList(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { VirtualFile[] projectFiles = FileEditorManager.getInstance(project).getSelectedFiles(); for (VirtualFile file : projectFiles) { if (file instanceof NewVirtualFile) { files.add(file); } } } if (!files.isEmpty()) { // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish RefreshQueue.getInstance().refresh(false, false, null, files); } }
public void testFindRootWithDenormalizedPath() { File tempDir = new WriteAction<File>() { @Override protected void run(Result<File> result) throws Throwable { File res = createTempDirectory(); new File(res, "x.jar").createNewFile(); result.setResult(res); } }.execute().getResultObject(); VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); VirtualFile jar = vDir.findChild("x.jar"); assertNotNull(jar); NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", JarFileSystem.getInstance()); NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//"+ jar.getName()+"!/", JarFileSystem.getInstance()); assertNotNull(root1); assertSame(root1, root2); }
public void testListChildrenOfTheRootOfTheRoot() { PersistentFS fs = PersistentFS.getInstance(); NewVirtualFile fakeRoot = fs.findRoot("", LocalFileSystem.getInstance()); assertNotNull(fakeRoot); int users = fs.getId(fakeRoot, "Users", LocalFileSystem.getInstance()); assertEquals(0, users); users = fs.getId(fakeRoot, "usr", LocalFileSystem.getInstance()); assertEquals(0, users); int win = fs.getId(fakeRoot, "Windows", LocalFileSystem.getInstance()); assertEquals(0, win); VirtualFile[] roots = fs.getRoots(LocalFileSystem.getInstance()); for (VirtualFile root : roots) { int rid = fs.getId(fakeRoot, root.getName(), LocalFileSystem.getInstance()); assertTrue(root.getPath()+"; Roots:"+ Arrays.toString(roots), 0 != rid); } NewVirtualFile c = fakeRoot.refreshAndFindChild("Users"); assertNull(c); c = fakeRoot.refreshAndFindChild("Users"); assertNull(c); c = fakeRoot.refreshAndFindChild("Windows"); assertNull(c); c = fakeRoot.refreshAndFindChild("Windows"); assertNull(c); }
public void testFindRootShouldNotBeFooledByRelativePath() throws IOException { File tmp = createTempDirectory(); File x = new File(tmp, "x.jar"); x.createNewFile(); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile vx = lfs.refreshAndFindFileByIoFile(x); assertNotNull(vx); JarFileSystem jfs = JarFileSystem.getInstance(); VirtualFile root = jfs.getJarRootForLocalFile(vx); PersistentFS fs = PersistentFS.getInstance(); String path = vx.getPath() + "/../" + vx.getName() + JarFileSystem.JAR_SEPARATOR; NewVirtualFile root1 = fs.findRoot(path, jfs); assertSame(root1, root); }
private static void refreshDeletedOrReplaced(final File root) { final File parent = root.getParentFile(); VirtualFile vf = null; // parent should also notice the change final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); final VirtualFile rootVf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(root); if (parent != null) { vf = localFileSystem.refreshAndFindFileByIoFile(parent); } if (vf == null) { vf = rootVf; } if (vf != null) { ((NewVirtualFile)vf).markDirtyRecursively(); vf.refresh(false, true); } }
private static VirtualFile refreshVFS(final File directory) { final Ref<VirtualFile> result = new Ref<VirtualFile>(); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { final LocalFileSystem lfs = LocalFileSystem.getInstance(); final VirtualFile vDir = lfs.refreshAndFindFileByIoFile(directory); result.set(vDir); if (vDir != null) { final LocalFileSystem.WatchRequest watchRequest = lfs.addRootToWatch(vDir.getPath(), true); ((NewVirtualFile)vDir).markDirtyRecursively(); vDir.refresh(false, true); if (watchRequest != null) { lfs.removeWatchedRoot(watchRequest); } } } }); return result.get(); }
@NotNull private DirectoryInfo with(int id, @NotNull DirectoryInfo info, Module module, VirtualFile contentRoot, VirtualFile sourceRoot, VirtualFile libraryClassRoot, @DirectoryInfo.SourceFlag int sourceFlag, OrderEntry[] orderEntries) { if (contentRoot != null) { assertAncestor(info, contentRoot, id); } if (sourceRoot instanceof NewVirtualFile) { VirtualFile root = contentRoot == null ? info.getContentRoot() : contentRoot; if (root != null) { assertAncestor(info, root, ((NewVirtualFile)sourceRoot).getId()); } } DirectoryInfo newInfo = info.with(module, contentRoot, sourceRoot, libraryClassRoot, (byte)sourceFlag, orderEntries); storeInfo(newInfo, id); return newInfo; }
private void initModuleContents(@NotNull Module module, boolean reverseAllSets, @NotNull ProgressIndicator progress) { assertWritable(); progress.checkCanceled(); progress.setText2(ProjectBundle.message("project.index.processing.module.content.progress", module.getName())); ModuleRootManager rootManager = ModuleRootManager.getInstance(module); VirtualFile[] contentRoots = rootManager.getContentRoots(); if (reverseAllSets) { contentRoots = ArrayUtil.reverseArray(contentRoots); } for (final VirtualFile contentRoot : contentRoots) { if (contentRoot instanceof NewVirtualFile) { fillMapWithModuleContent((NewVirtualFile)contentRoot, module, (NewVirtualFile)contentRoot, progress); } } }
private void initLibrarySources(@NotNull Module module, @NotNull ProgressIndicator progress, @Nullable TObjectIntHashMap<String> interned) { assertWritable(); progress.checkCanceled(); progress.setText2(ProjectBundle.message("project.index.processing.library.sources.progress", module.getName())); for (OrderEntry orderEntry : getOrderEntries(module)) { if (orderEntry instanceof LibraryOrSdkOrderEntry) { VirtualFile[] sourceRoots = ((LibraryOrSdkOrderEntry)orderEntry).getRootFiles(OrderRootType.SOURCES); for (final VirtualFile sourceRoot : sourceRoots) { if (sourceRoot instanceof NewVirtualFile) { fillMapWithLibrarySources((NewVirtualFile)sourceRoot, "", (NewVirtualFile)sourceRoot, progress, interned); } } } } }
private void initLibraryClasses(@NotNull Module module, @NotNull ProgressIndicator progress, @Nullable TObjectIntHashMap<String> interned) { assertWritable(); progress.checkCanceled(); progress.setText2(ProjectBundle.message("project.index.processing.library.classes.progress", module.getName())); for (OrderEntry orderEntry : getOrderEntries(module)) { if (orderEntry instanceof LibraryOrSdkOrderEntry) { VirtualFile[] classRoots = ((LibraryOrSdkOrderEntry)orderEntry).getRootFiles(OrderRootType.CLASSES); for (final VirtualFile classRoot : classRoots) { if (classRoot instanceof NewVirtualFile) { fillMapWithLibraryClasses((NewVirtualFile)classRoot, "", (NewVirtualFile)classRoot, progress, interned); } } } } }
private static Timestamps createOrGetTimeStamp(VirtualFile file) { if (file instanceof NewVirtualFile && file.isValid()) { Timestamps timestamps = myTimestampsCache.get(file); if (timestamps == null) { final DataInputStream stream = Timestamps.PERSISTENCE.readAttribute(file); try { timestamps = new Timestamps(stream); } catch (IOException e) { throw new RuntimeException(e); } myTimestampsCache.put(file, timestamps); } return timestamps; } return null; }
public void testFindRootWithDenormalizedPath() { File tempDir = new WriteAction<File>() { @Override protected void run(Result<File> result) throws Throwable { File res = createTempDirectory(); new File(res, "x.jar").createNewFile(); result.setResult(res); } }.execute().getResultObject(); VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); VirtualFile jar = vDir.findChild("x.jar"); assertNotNull(jar); NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", (NewVirtualFileSystem)StandardFileSystems.jar()); NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//"+ jar.getName()+"!/", (NewVirtualFileSystem)StandardFileSystems.jar()); assertNotNull(root1); assertSame(root1, root2); }
public void testFindRootShouldNotBeFooledByRelativePath() throws IOException { File tmp = createTempDirectory(); File x = new File(tmp, "x.jar"); x.createNewFile(); LocalFileSystem lfs = LocalFileSystem.getInstance(); VirtualFile vx = lfs.refreshAndFindFileByIoFile(x); assertNotNull(vx); ArchiveFileSystem jfs = (ArchiveFileSystem)StandardFileSystems.jar(); VirtualFile root = ArchiveVfsUtil.getArchiveRootForLocalFile(vx); PersistentFS fs = PersistentFS.getInstance(); String path = vx.getPath() + "/../" + vx.getName() + ArchiveFileSystem.ARCHIVE_SEPARATOR; NewVirtualFile root1 = fs.findRoot(path, (NewVirtualFileSystem)jfs); assertSame(root1, root); }
@Nonnull public static List<VirtualFile> markDirty(boolean recursive, boolean reloadChildren, @Nonnull VirtualFile... files) { List<VirtualFile> list = ContainerUtil.filter(files, Condition.NOT_NULL); if (list.isEmpty()) { return Collections.emptyList(); } for (VirtualFile file : list) { if (reloadChildren) { file.getChildren(); } if (file instanceof NewVirtualFile) { if (recursive) { ((NewVirtualFile)file).markDirtyRecursively(); } else { ((NewVirtualFile)file).markDirty(); } } } return list; }
/** * Sets specified read-only status for the spcified <code>file</code>. * This method can be performed only for files which are in local file system. * * @param file file which read-only attribute to be changed. * @param readOnlyStatus new read-only status. * @throws java.lang.IllegalArgumentException * if passed <code>file</code> doesn't * belong to the local file system. * @throws IOException if some <code>IOException</code> occurred. */ public static void setReadOnlyAttribute(VirtualFile file, boolean readOnlyStatus) throws IOException { if (file.getFileSystem().isReadOnly()) { throw new IllegalArgumentException("Wrong file system: " + file.getFileSystem()); } if (file.isWritable() == !readOnlyStatus) { return; } if (file instanceof NewVirtualFile) { ((NewVirtualFile)file).setWritable(!readOnlyStatus); } else { String path = file.getPresentableUrl(); setReadOnlyAttribute(path, readOnlyStatus); file.refresh(false, false); } }