Search in sources :

Example 6 with FileAttributes

use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.

the class RefreshWorker method partialDirRefresh.

private void partialDirRefresh(NewVirtualFileSystem fs, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
    while (true) {
        // obtaining directory snapshot
        List<VirtualFile> cached;
        List<String> wanted;
        AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            cached = dir.getCachedChildren();
            wanted = dir.getSuspiciousNames();
        } finally {
            token.finish();
        }
        OpenTHashSet<String> actualNames = null;
        if (!fs.isCaseSensitive()) {
            actualNames = new OpenTHashSet<>(strategy, VfsUtil.filterNames(fs.list(dir)));
        }
        if (LOG.isTraceEnabled()) {
            LOG.trace("cached=" + cached + " actual=" + actualNames);
            LOG.trace("suspicious=" + wanted);
        }
        // reading children attributes
        List<Pair<VirtualFile, FileAttributes>> existingMap = ContainerUtil.newArrayListWithCapacity(cached.size());
        for (VirtualFile child : cached) {
            checkCancelled(dir);
            existingMap.add(pair(child, fs.getAttributes(child)));
        }
        List<Pair<String, FileAttributes>> wantedMap = ContainerUtil.newArrayListWithCapacity(wanted.size());
        for (String name : wanted) {
            if (name.isEmpty())
                continue;
            checkCancelled(dir);
            wantedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
        }
        // generating events unless a directory was changed in between
        token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            if (!cached.equals(dir.getCachedChildren()) || !wanted.equals(dir.getSuspiciousNames())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("retry: " + dir);
                continue;
            }
            for (Pair<VirtualFile, FileAttributes> pair : existingMap) {
                VirtualFile child = pair.first;
                FileAttributes childAttributes = pair.second;
                if (childAttributes != null) {
                    checkAndScheduleChildRefresh(dir, child, childAttributes);
                    checkAndScheduleFileNameChange(actualNames, child);
                } else {
                    scheduleDeletion(child);
                }
            }
            for (Pair<String, FileAttributes> pair : wantedMap) {
                String name = pair.first;
                FileAttributes childAttributes = pair.second;
                if (childAttributes != null) {
                    scheduleCreation(dir, name, childAttributes.isDirectory(), false);
                }
            }
            break;
        } finally {
            token.finish();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Pair(com.intellij.openapi.util.Pair)

Example 7 with FileAttributes

use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.

the class CoreJarHandler method getOrCreateFile.

@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;
}
Also used : FileAttributes(com.intellij.openapi.util.io.FileAttributes) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with FileAttributes

use of com.intellij.openapi.util.io.FileAttributes 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 9 with FileAttributes

use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.

the class RefreshWorker method fullDirRefresh.

private void fullDirRefresh(NewVirtualFileSystem fs, PersistentFS persistence, TObjectHashingStrategy<String> strategy, VirtualDirectoryImpl dir) {
    while (true) {
        // obtaining directory snapshot
        String[] currentNames;
        VirtualFile[] children;
        AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            currentNames = persistence.list(dir);
            children = dir.getChildren();
        } finally {
            token.finish();
        }
        // reading children attributes
        String[] upToDateNames = VfsUtil.filterNames(fs.list(dir));
        Set<String> newNames = newTroveSet(strategy, upToDateNames);
        ContainerUtil.removeAll(newNames, currentNames);
        Set<String> deletedNames = newTroveSet(strategy, currentNames);
        ContainerUtil.removeAll(deletedNames, upToDateNames);
        OpenTHashSet<String> actualNames = null;
        if (!fs.isCaseSensitive()) {
            actualNames = new OpenTHashSet<>(strategy, upToDateNames);
        }
        if (LOG.isTraceEnabled())
            LOG.trace("current=" + Arrays.toString(currentNames) + " +" + newNames + " -" + deletedNames);
        List<Pair<String, FileAttributes>> addedMap = ContainerUtil.newArrayListWithCapacity(newNames.size());
        for (String name : newNames) {
            checkCancelled(dir);
            addedMap.add(pair(name, fs.getAttributes(new FakeVirtualFile(dir, name))));
        }
        List<Pair<VirtualFile, FileAttributes>> updatedMap = ContainerUtil.newArrayListWithCapacity(children.length);
        for (VirtualFile child : children) {
            if (deletedNames.contains(child.getName()))
                continue;
            checkCancelled(dir);
            updatedMap.add(pair(child, fs.getAttributes(child)));
        }
        // generating events unless a directory was changed in between
        token = ApplicationManager.getApplication().acquireReadActionLock();
        try {
            if (!Arrays.equals(currentNames, persistence.list(dir)) || !Arrays.equals(children, dir.getChildren())) {
                if (LOG.isDebugEnabled())
                    LOG.debug("retry: " + dir);
                continue;
            }
            for (String name : deletedNames) {
                scheduleDeletion(dir.findChild(name));
            }
            for (Pair<String, FileAttributes> pair : addedMap) {
                String name = pair.first;
                FileAttributes childAttributes = pair.second;
                if (childAttributes != null) {
                    scheduleCreation(dir, name, childAttributes.isDirectory(), false);
                } else {
                    LOG.warn("[+] fs=" + fs + " dir=" + dir + " name=" + name);
                }
            }
            for (Pair<VirtualFile, FileAttributes> pair : updatedMap) {
                VirtualFile child = pair.first;
                FileAttributes childAttributes = pair.second;
                if (childAttributes != null) {
                    checkAndScheduleChildRefresh(dir, child, childAttributes);
                    checkAndScheduleFileNameChange(actualNames, child);
                } else {
                    LOG.warn("[x] fs=" + fs + " dir=" + dir + " name=" + child.getName());
                    scheduleDeletion(child);
                }
            }
            break;
        } finally {
            token.finish();
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) FakeVirtualFile(com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Pair(com.intellij.openapi.util.Pair)

Example 10 with FileAttributes

use of com.intellij.openapi.util.io.FileAttributes in project intellij-community by JetBrains.

the class VirtualDirectoryImpl method createAndFindChildWithEventFire.

@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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VFileCreateEvent(com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FileAttributes (com.intellij.openapi.util.io.FileAttributes)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)4 AccessToken (com.intellij.openapi.application.AccessToken)2 Pair (com.intellij.openapi.util.Pair)2 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 FakeVirtualFile (com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile)2 THashMap (gnu.trove.THashMap)2 ZipFile (java.util.zip.ZipFile)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 JarFileSystemImpl (com.intellij.openapi.vfs.impl.jar.JarFileSystemImpl)1 JarHandler (com.intellij.openapi.vfs.impl.jar.JarHandler)1 VFileCreateEvent (com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent)1 VirtualDirectoryImpl (com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 Field (java.lang.reflect.Field)1