Search in sources :

Example 16 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class RefreshWorker method processQueue.

private void processQueue(NewVirtualFileSystem fs, PersistentFS persistence) throws RefreshCancelledException {
    TObjectHashingStrategy<String> strategy = FilePathHashingStrategy.create(fs.isCaseSensitive());
    while (!myRefreshQueue.isEmpty()) {
        Pair<NewVirtualFile, FileAttributes> pair = myRefreshQueue.pullFirst();
        NewVirtualFile file = pair.first;
        boolean fileDirty = file.isDirty();
        if (LOG.isTraceEnabled())
            LOG.trace("file=" + file + " dirty=" + fileDirty);
        if (!fileDirty)
            continue;
        checkCancelled(file);
        FileAttributes attributes = pair.second != null ? pair.second : fs.getAttributes(file);
        if (attributes == null) {
            scheduleDeletion(file);
            file.markClean();
            continue;
        }
        NewVirtualFile parent = file.getParent();
        if (parent != null && checkAndScheduleFileTypeChange(parent, file, attributes)) {
            // ignore everything else
            file.markClean();
            continue;
        }
        if (file.isDirectory()) {
            boolean fullSync = ((VirtualDirectoryImpl) file).allChildrenLoaded();
            if (fullSync) {
                fullDirRefresh(fs, persistence, strategy, (VirtualDirectoryImpl) file);
            } else {
                partialDirRefresh(fs, strategy, (VirtualDirectoryImpl) file);
            }
        } else {
            long currentTimestamp = persistence.getTimeStamp(file);
            long upToDateTimestamp = attributes.lastModified;
            long currentLength = persistence.getLastRecordedLength(file);
            long upToDateLength = attributes.length;
            if (currentTimestamp != upToDateTimestamp || currentLength != upToDateLength) {
                scheduleUpdateContent(file);
            }
        }
        boolean currentWritable = persistence.isWritable(file);
        boolean upToDateWritable = attributes.isWritable();
        if (LOG_ATTRIBUTES.isDebugEnabled()) {
            LOG_ATTRIBUTES.debug("file=" + file + " writable vfs=" + file.isWritable() + " persistence=" + currentWritable + " real=" + upToDateWritable);
        }
        if (currentWritable != upToDateWritable) {
            scheduleAttributeChange(file, VirtualFile.PROP_WRITABLE, currentWritable, upToDateWritable);
        }
        if (SystemInfo.isWindows) {
            boolean currentHidden = file.is(VFileProperty.HIDDEN);
            boolean upToDateHidden = attributes.isHidden();
            if (currentHidden != upToDateHidden) {
                scheduleAttributeChange(file, VirtualFile.PROP_HIDDEN, currentHidden, upToDateHidden);
            }
        }
        if (attributes.isSymLink()) {
            String currentTarget = file.getCanonicalPath();
            String upToDateTarget = fs.resolveSymLink(file);
            String upToDateVfsTarget = upToDateTarget != null ? FileUtil.toSystemIndependentName(upToDateTarget) : null;
            if (!Comparing.equal(currentTarget, upToDateVfsTarget)) {
                scheduleAttributeChange(file, VirtualFile.PROP_SYMLINK_TARGET, currentTarget, upToDateVfsTarget);
            }
        }
        if (myIsRecursive || !file.isDirectory()) {
            file.markClean();
        }
    }
}
Also used : VirtualDirectoryImpl(com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) FileAttributes(com.intellij.openapi.util.io.FileAttributes)

Example 17 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class RefreshWorker method scan.

public void scan() {
    NewVirtualFile root = myRefreshQueue.peekFirst().first;
    NewVirtualFileSystem fs = root.getFileSystem();
    if (root.isDirectory()) {
        fs = PersistentFS.replaceWithNativeFS(fs);
    }
    try {
        processQueue(fs, PersistentFS.getInstance());
    } catch (RefreshCancelledException e) {
        LOG.debug("refresh cancelled");
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) NewVirtualFileSystem(com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem)

Example 18 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class MacPythonSdkFlavor method collectPythonInstallations.

private static void collectPythonInstallations(String pythonPath, Set<String> candidates) {
    VirtualFile rootVDir = LocalFileSystem.getInstance().findFileByPath(pythonPath);
    if (rootVDir != null) {
        if (rootVDir instanceof NewVirtualFile) {
            ((NewVirtualFile) rootVDir).markDirty();
        }
        rootVDir.refresh(true, false);
        for (VirtualFile dir : rootVDir.getChildren()) {
            final String dirName = dir.getName().toLowerCase();
            if (dir.isDirectory()) {
                if ("Current".equals(dirName) || dirName.startsWith("2") || dirName.startsWith("3")) {
                    final VirtualFile binDir = dir.findChild("bin");
                    if (binDir != null && binDir.isDirectory()) {
                        for (String name : POSSIBLE_BINARY_NAMES) {
                            final VirtualFile child = binDir.findChild(name);
                            if (child == null)
                                continue;
                            String path = child.getPath();
                            if (FileSystemUtil.isSymLink(path)) {
                                path = FileSystemUtil.resolveSymLink(path);
                            }
                            if (path != null && !candidates.contains(path)) {
                                candidates.add(path);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Aggregations

NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 File (java.io.File)4 VirtualDirectoryImpl (com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 JobLauncher (com.intellij.concurrency.JobLauncher)1 JobSchedulerImpl (com.intellij.concurrency.JobSchedulerImpl)1 Language (com.intellij.lang.Language)1 ParserDefinition (com.intellij.lang.ParserDefinition)1 Application (com.intellij.openapi.application.Application)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 Ref (com.intellij.openapi.util.Ref)1