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"); } }
private boolean checkAndScheduleFileTypeChange(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL); boolean upToDateIsDirectory = childAttributes.isDirectory(); boolean upToDateIsSymlink = childAttributes.isSymLink(); boolean upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { scheduleDeletion(child); scheduleCreation(parent, child.getName(), upToDateIsDirectory, true); return true; } return false; }
static void writeAttributesToRecord(int id, int parentId, @NotNull FileAttributes attributes, @NotNull String name) { w.lock(); try { setName(id, name); setTimestamp(id, attributes.lastModified); setLength(id, attributes.isDirectory() ? -1L : attributes.length); setFlags(id, (attributes.isDirectory() ? PersistentFS.IS_DIRECTORY_FLAG : 0) | (attributes.isWritable() ? 0 : PersistentFS.IS_READ_ONLY) | (attributes.isSymLink() ? PersistentFS.IS_SYMLINK : 0) | (attributes.isSpecial() ? PersistentFS.IS_SPECIAL : 0) | (attributes.isHidden() ? PersistentFS.IS_HIDDEN : 0), true); setParent(id, parentId); } catch (Throwable e) { throw DbConnection.handleError(e); } finally { w.unlock(); } }
private File getMirrorFile(@NotNull File originalFile) { if (!myFileSystem.isMakeCopyOfJar(originalFile)) return originalFile; final FileAttributes originalAttributes = FileSystemUtil.getAttributes(originalFile); if (originalAttributes == null) return originalFile; final String folderPath = getJarsDir(); if (!new File(folderPath).exists() && !new File(folderPath).mkdirs()) { return originalFile; } if (FSRecords.weHaveContentHashes) { return getMirrorWithContentHash(originalFile, originalAttributes); } final String mirrorName = originalFile.getName() + "." + Integer.toHexString(originalFile.getPath().hashCode()); final File mirrorFile = new File(folderPath, mirrorName); final FileAttributes mirrorAttributes = FileSystemUtil.getAttributes(mirrorFile); return mirrorDiffers(originalAttributes, mirrorAttributes, false) ? copyToMirror(originalFile, mirrorFile) : mirrorFile; }
@NotNull String[] list(@NotNull String path) { FileInfo[] fileInfo = myKernel.listChildren(path); if (fileInfo == null || fileInfo.length == 0) { return ArrayUtil.EMPTY_STRING_ARRAY; } if (!StringUtil.endsWithChar(path, '/')) path += "/"; String[] names = new String[fileInfo.length]; Map<String, FileAttributes> map = getMap(); for (int i = 0, length = fileInfo.length; i < length; i++) { FileInfo info = fileInfo[i]; String name = info.getName(); map.put(path + name, info.toFileAttributes()); names[i] = name; } return names; }
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (!myProject.isDisposed() && !GeneralSettings.getInstance().isSyncOnFrameActivation()) { VirtualFileSystem fs = file.getFileSystem(); if (fs instanceof LocalFileSystem) { FileAttributes attributes = ((LocalFileSystem)fs).getAttributes(file); if (attributes == null || file.getTimeStamp() != attributes.lastModified || file.getLength() != attributes.length) { LogUtil.debug(LOG, "%s: (%s,%s) -> %s", file, file.getTimeStamp(), file.getLength(), attributes); return createPanel(file); } } } return null; }
private boolean checkAndScheduleAttributesChange(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL); boolean upToDateIsDirectory = childAttributes.isDirectory(); boolean upToDateIsSymlink = childAttributes.isSymLink(); boolean upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { scheduleDeletion(child); scheduleReCreation(parent, child.getName(), upToDateIsDirectory); return true; } return false; }
private boolean checkAndScheduleSymLinkTargetChange(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes, @NotNull NewVirtualFileSystem fs) { if (childAttributes.isSymLink()) { String currentTarget = child.getCanonicalPath(); String upToDateTarget = fs.resolveSymLink(child); String upToDateVfsTarget = upToDateTarget != null ? FileUtil.toSystemIndependentName(upToDateTarget) : null; if (!Comparing.equal(currentTarget, upToDateVfsTarget)) { scheduleDeletion(child); scheduleReCreation(parent, child.getName(), childAttributes.isDirectory()); return true; } } return false; }
@Override public FileAttributes getAttributes(@NotNull final VirtualFile file) { final JarHandler handler = getHandler(file); if (handler == null) return null; if (file.getParent() == null) { final LocalFileSystem localFileSystem = LocalFileSystem.getInstance(); final VirtualFile originalFile = localFileSystem.findFileByIoFile(handler.getOriginalFile()); if (originalFile == null) return null; final FileAttributes attributes = localFileSystem.getAttributes(originalFile); if (attributes == null) return null; return new FileAttributes(true, false, false, false, attributes.length, attributes.lastModified, attributes.isWritable()); } return handler.getAttributes(file); }
@NotNull String[] list(@NotNull String path) { FileInfo[] fileInfo = myKernel.listChildren(path); if (fileInfo == null || fileInfo.length == 0) { return ArrayUtil.EMPTY_STRING_ARRAY; } if (!path.endsWith("/")) path += "/"; List<String> names = new ArrayList<String>(fileInfo.length); Map<String, FileAttributes> map = getMap(); for (FileInfo info : fileInfo) { String name = info.getName(); map.put(path + name, info.toFileAttributes()); names.add(name); } return ArrayUtil.toStringArray(names); }
public void scan() { NewVirtualFile root = myRefreshQueue.pullFirst().first; boolean rootDirty = root.isDirty(); if (LOG.isDebugEnabled()) LOG.debug("root=" + root + " dirty=" + 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"); } }
private boolean checkAndScheduleFileTypeChange(@Nonnull VirtualFile parent, @Nonnull VirtualFile child, @Nonnull FileAttributes childAttributes) { boolean currentIsDirectory = child.isDirectory(); boolean currentIsSymlink = child.is(VFileProperty.SYMLINK); boolean currentIsSpecial = child.is(VFileProperty.SPECIAL); boolean upToDateIsDirectory = childAttributes.isDirectory(); boolean upToDateIsSymlink = childAttributes.isSymLink(); boolean upToDateIsSpecial = childAttributes.isSpecial(); if (currentIsDirectory != upToDateIsDirectory || currentIsSymlink != upToDateIsSymlink || currentIsSpecial != upToDateIsSpecial) { scheduleDeletion(child); scheduleCreation(parent, child.getName(), upToDateIsDirectory, true); return true; } return false; }
static void writeAttributesToRecord(int id, int parentId, @Nonnull FileAttributes attributes, @Nonnull String name) { w.lock(); try { setName(id, name); setTimestamp(id, attributes.lastModified); setLength(id, attributes.isDirectory() ? -1L : attributes.length); setFlags(id, (attributes.isDirectory() ? PersistentFS.IS_DIRECTORY_FLAG : 0) | (attributes.isWritable() ? 0 : PersistentFS.IS_READ_ONLY) | (attributes.isSymLink() ? PersistentFS.IS_SYMLINK : 0) | (attributes.isSpecial() ? PersistentFS.IS_SPECIAL : 0) | (attributes.isHidden() ? PersistentFS.IS_HIDDEN : 0), true); setParent(id, parentId); } catch (Throwable e) { throw DbConnection.handleError(e); } finally { w.unlock(); } }
private File getMirrorFile(@Nonnull File originalFile) { if (!myFileSystem.isMakeCopyOfJar(originalFile)) return originalFile; final FileAttributes originalAttributes = FileSystemUtil.getAttributes(originalFile); if (originalAttributes == null) return originalFile; final String folderPath = getJarsDir(); if (!new File(folderPath).exists() && !new File(folderPath).mkdirs()) { return originalFile; } if (FSRecords.weHaveContentHashes) { return getMirrorWithContentHash(originalFile, originalAttributes); } final String mirrorName = originalFile.getName() + "." + Integer.toHexString(originalFile.getPath().hashCode()); final File mirrorFile = new File(folderPath, mirrorName); final FileAttributes mirrorAttributes = FileSystemUtil.getAttributes(mirrorFile); return mirrorDiffers(originalAttributes, mirrorAttributes, false) ? copyToMirror(originalFile, mirrorFile) : mirrorFile; }
@Nonnull String[] list(@Nonnull VirtualFile file) { String path = file.getPath(); FileInfo[] fileInfo = myKernel.listChildren(path); if (fileInfo == null || fileInfo.length == 0) { return ArrayUtil.EMPTY_STRING_ARRAY; } String[] names = new String[fileInfo.length]; TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap(); int parentId = ((VirtualFileWithId)file).getId(); THashMap<String, FileAttributes> nestedMap = map.get(parentId); if (nestedMap == null) { nestedMap = new THashMap<String, FileAttributes>(fileInfo.length, FileUtil.PATH_HASHING_STRATEGY); map.put(parentId, nestedMap); } for (int i = 0, length = fileInfo.length; i < length; i++) { FileInfo info = fileInfo[i]; String name = info.getName(); nestedMap.put(name, info.toFileAttributes()); names[i] = name; } return names; }
@Nullable FileAttributes getAttributes(@Nonnull VirtualFile file) { VirtualFile parent = file.getParent(); int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId)parent).getId() : -((VirtualFileWithId)file).getId(); TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap(); THashMap<String, FileAttributes> nestedMap = map.get(parentId); String name = file.getName(); FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null; if (attributes == null) { if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) { return null; // our info from parent doesn't mention the child in this refresh session } FileInfo info = myKernel.getInfo(file.getPath()); if (info == null) { return null; } attributes = info.toFileAttributes(); if (nestedMap == null) { nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY); map.put(parentId, nestedMap); } nestedMap.put(name, attributes); } return attributes; }
@RequiredReadAction @Nullable @Override public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) { if (!myProject.isDisposed() && !GeneralSettings.getInstance().isSyncOnFrameActivation()) { VirtualFileSystem fs = file.getFileSystem(); if (fs instanceof LocalFileSystem) { FileAttributes attributes = ((LocalFileSystem)fs).getAttributes(file); if (attributes == null || file.getTimeStamp() != attributes.lastModified || file.getLength() != attributes.length) { LogUtil.debug(LOG, "%s: (%s,%s) -> %s", file, file.getTimeStamp(), file.getLength(), attributes); return createPanel(file); } } } return null; }
@Nonnull private FileAccessorCache.Handle<ArchiveFile> getZipFileHandle() throws IOException { FileAccessorCache.Handle<ArchiveFile> handle = ourZipFileFileAccessorCache.get(this); if (getFile() == getFileToUse()) { // files are canonicalized // IDEA-148458, http://bugs.java.com/view_bug.do?bug_id=4425695, JVM crashes on use of opened ZipFile after it was updated // Reopen file if the file has been changed FileAttributes attributes = FileSystemUtil.getAttributes(getCanonicalPathToZip()); if (attributes == null) { throw new FileNotFoundException(getCanonicalPathToZip()); } if (attributes.lastModified == myFileStamp && attributes.length == myFileLength) return handle; // Note that zip_util.c#ZIP_Get_From_Cache will allow us to have duplicated ZipFile instances without a problem removeZipHandlerFromCache(); handle.release(); handle = ourZipFileFileAccessorCache.get(this); } return handle; }
@Override public long getTimeStamp(@NotNull VirtualFile file) { if (file.getParent() == null) { VirtualFile host = getLocalByEntry(file); if (host != null) return host.getTimeStamp(); } else { FileAttributes attributes = getAttributes(file); if (attributes != null) return attributes.lastModified; } return ArchiveHandler.DEFAULT_TIMESTAMP; }
@Override public long getLength(@NotNull VirtualFile file) { if (file.getParent() == null) { VirtualFile host = getLocalByEntry(file); if (host != null) return host.getLength(); } else { FileAttributes attributes = getAttributes(file); if (attributes != null) return attributes.length; } return ArchiveHandler.DEFAULT_LENGTH; }
@Nullable public FileAttributes getAttributes(@NotNull String relativePath) { if (relativePath.isEmpty()) { FileAttributes attributes = FileSystemUtil.getAttributes(myPath); return attributes != null ? new FileAttributes(true, false, false, false, DEFAULT_LENGTH, DEFAULT_TIMESTAMP, false) : null; } else { EntryInfo entry = getEntryInfo(relativePath); return entry != null ? new FileAttributes(entry.isDirectory, false, false, false, entry.length, entry.timestamp, false) : null; } }
@Override public FileAttributes getAttributes(@NotNull final VirtualFile file) { final FSItem item = convert(file); if (item == null) return null; final long length = item instanceof FSFile ? ((FSFile)item).myContent.length : 0; return new FileAttributes(item.isDirectory(), false, false, false, length, item.myTimestamp, item.myWritable); }
@Nullable private VirtualFileSystemEntry createAndFindChildWithEventFire(@NotNull String name, @NotNull NewVirtualFileSystem delegate) { final VirtualFile fake = new FakeVirtualFile(this, name); final FileAttributes attributes = delegate.getAttributes(fake); if (attributes == null) return null; final String realName = delegate.getCanonicallyCasedName(fake); final VFileCreateEvent event = new VFileCreateEvent(null, this, realName, attributes.isDirectory(), true); RefreshQueue.getInstance().processSingleEvent(event); return findChild(realName); }
private void checkAndScheduleChildRefresh(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes) { if (!checkAndScheduleFileTypeChange(parent, child, childAttributes)) { boolean upToDateIsDirectory = childAttributes.isDirectory(); if (myIsRecursive || !upToDateIsDirectory) { myRefreshQueue.addLast(Pair.create((NewVirtualFile)child, childAttributes)); } } }
@NotNull private static File convertToIOFileAndCheck(@NotNull final VirtualFile file) throws FileNotFoundException { final File ioFile = convertToIOFile(file); final FileAttributes attributes = FileSystemUtil.getAttributes(ioFile); if (attributes != null && !attributes.isFile()) { LOG.warn("not a file: " + ioFile + ", " + attributes); throw new FileNotFoundException("Not a file: " + ioFile); } return ioFile; }
@Override public FileAttributes getAttributes(@NotNull final VirtualFile file) { String path = normalize(file.getPath()); if (path == null) return null; if (file.getParent() == null && path.startsWith("//")) { return FAKE_ROOT_ATTRIBUTES; // fake Windows roots } return FileSystemUtil.getAttributes(FileUtil.toSystemDependentName(path)); }
@NotNull private Map<String, FileAttributes> getMap() { Map<String, FileAttributes> map = com.intellij.reference.SoftReference.dereference(myCache); if (map == null) { map = new THashMap<String, FileAttributes>(FileUtil.PATH_HASHING_STRATEGY); myCache = new SoftReference<Map<String, FileAttributes>>(map); } return map; }
@Nullable FileAttributes getAttributes(@NotNull VirtualFile file) { String path = file.getPath(); Map<String, FileAttributes> map = getMap(); FileAttributes attributes = map.get(path); if (attributes == null) { FileInfo info = myKernel.getInfo(path); if (info == null) { return null; } attributes = info.toFileAttributes(); map.put(path, attributes); } return attributes; }
public void testWindowsHiddenDirectory() throws Exception { if (!SystemInfo.isWindows) { System.err.println(getName() + " skipped: " + SystemInfo.OS_NAME); return; } File file = new File("C:\\Documents and Settings\\desktop.ini"); if (!file.exists()) { System.err.println(getName() + " skipped: missing " + file); return; } String parent = FileUtil.toSystemIndependentName(file.getParent()); VfsRootAccess.allowRootAccess(parent); try { VirtualFile virtualFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(virtualFile); NewVirtualFileSystem fs = (NewVirtualFileSystem)virtualFile.getFileSystem(); FileAttributes attributes = fs.getAttributes(virtualFile); assertNotNull(attributes); assertEquals(FileAttributes.Type.FILE, attributes.type); assertEquals(FileAttributes.HIDDEN, attributes.flags); } finally { VfsRootAccess.disallowRootAccess(parent); } }
@NotNull public FileAttributes toFileAttributes() { if (attributes == BROKEN_SYMLINK) return FileAttributes.BROKEN_SYMLINK; final boolean isDirectory = isSet(attributes, FILE_ATTRIBUTE_DIRECTORY); final boolean isSpecial = isSet(attributes, FILE_ATTRIBUTE_DEVICE); final boolean isSymlink = isSet(attributes, FILE_ATTRIBUTE_REPARSE_POINT); final boolean isHidden = isSet(attributes, FILE_ATTRIBUTE_HIDDEN); final boolean isWritable = !isSet(attributes, FILE_ATTRIBUTE_READONLY); final long javaTimestamp = timestamp / 10000 - 11644473600000l; return new FileAttributes(isDirectory, isSpecial, isSymlink, isHidden, length, javaTimestamp, isWritable); }
@NotNull private CoreJarVirtualFile getOrCreateFile(@NotNull EntryInfo info, @NotNull Map<EntryInfo, CoreJarVirtualFile> entries) { CoreJarVirtualFile file = entries.get(info); if (file == null) { FileAttributes attributes = new FileAttributes(info.isDirectory, false, false, false, info.length, info.timestamp, false); EntryInfo parent = info.parent; file = new CoreJarVirtualFile(this, info.shortName.toString(), attributes, parent != null ? getOrCreateFile(parent, entries) : null); entries.put(info, file); } return file; }
public CoreJarVirtualFile(@NotNull CoreJarHandler handler, @NotNull String name, @NotNull FileAttributes entry, @Nullable CoreJarVirtualFile parent) { myHandler = handler; myName = name; myEntry = entry; myParent = parent; if (parent != null) { if (parent.myChildren == null) { parent.myChildren = new SmartList<VirtualFile>(); } parent.myChildren.add(this); } }
private void checkAndScheduleChildRefresh(@NotNull VirtualFile parent, @NotNull VirtualFile child, @NotNull FileAttributes childAttributes) { if (!checkAndScheduleAttributesChange(parent, child, childAttributes)) { boolean upToDateIsDirectory = childAttributes.isDirectory(); if (myIsRecursive || !upToDateIsDirectory) { myRefreshQueue.addLast(Pair.create((NewVirtualFile)child, childAttributes)); } } }
@Override public File getMirrorFile(@NotNull File originalFile) { if (!myFileSystem.isMakeCopyOfJar(originalFile)) return originalFile; final FileAttributes originalAttributes = FileSystemUtil.getAttributes(originalFile); if (originalAttributes == null) return originalFile; final String folderPath = getJarsDir(); if (!new File(folderPath).exists() && !new File(folderPath).mkdirs()) { return originalFile; } if (FSRecords.weHaveContentHashes) { return getMirrorWithContentHash(originalFile, originalAttributes); } final String mirrorName = originalFile.getName() + "." + Integer.toHexString(originalFile.getPath().hashCode()); final File mirrorFile = new File(folderPath, mirrorName); final FileAttributes mirrorAttributes = FileSystemUtil.getAttributes(mirrorFile); if (mirrorAttributes == null || originalAttributes.length != mirrorAttributes.length || Math.abs(originalAttributes.lastModified - mirrorAttributes.lastModified) > FS_TIME_RESOLUTION) { return copyToMirror(originalFile, mirrorFile); } return mirrorFile; }
@NotNull private Map<String, FileAttributes> getMap() { Reference<Map<String, FileAttributes>> cache = myCache; Map<String, FileAttributes> map = cache == null ? null : cache.get(); if (map == null) { map = new THashMap<String, FileAttributes>(); myCache = new SoftReference<Map<String, FileAttributes>>(map); } return map; }