Search in sources :

Example 1 with InvalidVirtualFileAccessException

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

the class VirtualDirectoryImpl method doFindChild.

// null if there can't be a child with this name, NULL_VIRTUAL_FILE if cached as absent, the file if found
@Nullable
private VirtualFileSystemEntry doFindChild(@NotNull String name, boolean ensureCanonicalName, @NotNull NewVirtualFileSystem delegate, boolean ignoreCase) {
    if (name.isEmpty()) {
        return null;
    }
    if (!isValid()) {
        throw new InvalidVirtualFileAccessException(this);
    }
    VirtualFileSystemEntry found = doFindChildInArray(name, ignoreCase);
    if (found != null)
        return found;
    if (ensureCanonicalName) {
        String canonicalName = UriUtil.trimTrailingSlashes(UriUtil.trimLeadingSlashes(FileUtilRt.toSystemIndependentName(name)));
        // name must not contain slashes in the middle
        if (canonicalName.indexOf('/') != -1)
            return null;
        VirtualFile fake = new FakeVirtualFile(this, canonicalName);
        canonicalName = delegate.getCanonicallyCasedName(fake);
        if (canonicalName.isEmpty())
            return null;
        if (!canonicalName.equals(name)) {
            found = doFindChildInArray(canonicalName, ignoreCase);
            if (found != null)
                return found;
            name = canonicalName;
        }
    }
    if (allChildrenLoaded()) {
        return NULL_VIRTUAL_FILE;
    }
    VirtualFileSystemEntry child;
    synchronized (myData) {
        // maybe another doFindChild() sneaked in the middle
        if (myData.isAdoptedName(name))
            return NULL_VIRTUAL_FILE;
        int[] array = myData.myChildrenIds;
        int indexInReal = findIndex(array, name, ignoreCase);
        // double check
        if (indexInReal >= 0) {
            return VfsData.getFileById(array[indexInReal], this);
        }
        if (allChildrenLoaded()) {
            return null;
        }
        // do not extract getId outside the synchronized block since it will cause a concurrency problem.
        int id = ourPersistence.getId(this, name, delegate);
        if (id <= 0) {
            myData.addAdoptedName(name, !ignoreCase);
            return null;
        }
        child = createChild(FileNameCache.storeName(name), id, delegate);
        int[] after = myData.myChildrenIds;
        if (after != array) {
            // in tests when we call assertAccessInTests it can load a huge number of files which lead to children modification
            // so fall back to slow path
            addChild(child);
        } else {
            insertChildAt(child, indexInReal);
            assertConsistency(!delegate.isCaseSensitive(), name);
        }
    }
    if (!child.isDirectory()) {
        // access check should only be called when child is actually added to the parent, otherwise it may break VirtualFilePointers validity
        //noinspection TestOnlyProblems
        VfsRootAccess.assertAccessInTests(child, getFileSystem());
    }
    return child;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) InvalidVirtualFileAccessException(com.intellij.openapi.vfs.InvalidVirtualFileAccessException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with InvalidVirtualFileAccessException

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

the class IndexingStamp method getNontrivialFileIndexedStates.

@NotNull
public static List<ID<?, ?>> getNontrivialFileIndexedStates(int fileId) {
    if (fileId != INVALID_FILE_ID) {
        Lock readLock = getStripedLock(fileId).readLock();
        readLock.lock();
        try {
            Timestamps stamp = createOrGetTimeStamp(fileId);
            if (stamp != null && stamp.myIndexStamps != null && !stamp.myIndexStamps.isEmpty()) {
                final SmartList<ID<?, ?>> retained = new SmartList<>();
                stamp.myIndexStamps.forEach(new TObjectProcedure<ID<?, ?>>() {

                    @Override
                    public boolean execute(ID<?, ?> object) {
                        retained.add(object);
                        return true;
                    }
                });
                return retained;
            }
        } catch (InvalidVirtualFileAccessException ignored) /*ok to ignore it here*/
        {
        } finally {
            readLock.unlock();
        }
    }
    return Collections.emptyList();
}
Also used : SmartList(com.intellij.util.SmartList) InvalidVirtualFileAccessException(com.intellij.openapi.vfs.InvalidVirtualFileAccessException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with InvalidVirtualFileAccessException

use of com.intellij.openapi.vfs.InvalidVirtualFileAccessException in project intellij-plugins by JetBrains.

the class BundleManifestCache method readProperties.

private static BundleManifest readProperties(PsiFile propertiesFile) {
    try {
        UTF8Properties properties = new UTF8Properties();
        properties.load(new StringReader(propertiesFile.getText()));
        Map<String, String> map = ContainerUtil.newHashMap();
        for (Object key : properties.keySet()) {
            String name = key.toString();
            map.put(name, properties.getProperty(name));
        }
        if (map.get(Constants.BUNDLE_SYMBOLICNAME) == null) {
            VirtualFile file = propertiesFile.getVirtualFile();
            if (file != null) {
                if (!BndProjectImporter.BND_FILE.equals(file.getName())) {
                    map.put(Constants.BUNDLE_SYMBOLICNAME, FileUtil.getNameWithoutExtension(file.getName()));
                } else if (file.getParent() != null) {
                    map.put(Constants.BUNDLE_SYMBOLICNAME, file.getParent().getName());
                }
            }
        }
        return new BundleManifest(map, propertiesFile);
    } catch (IOException ignored) {
    } catch (InvalidVirtualFileAccessException ignored) {
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringReader(java.io.StringReader) IOException(java.io.IOException) InvalidVirtualFileAccessException(com.intellij.openapi.vfs.InvalidVirtualFileAccessException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 4 with InvalidVirtualFileAccessException

use of com.intellij.openapi.vfs.InvalidVirtualFileAccessException in project intellij-plugins by JetBrains.

the class BundleManifestCache method readManifest.

private static BundleManifest readManifest(ManifestFile manifestFile) {
    try {
        ByteArrayInputStream stream = new ByteArrayInputStream(manifestFile.getText().getBytes(CharsetToolkit.UTF8));
        Attributes attributes = new Manifest(stream).getMainAttributes();
        Map<String, String> map = ContainerUtil.newHashMap();
        for (Object key : attributes.keySet()) {
            String name = key.toString();
            map.put(name, attributes.getValue(name));
        }
        return new BundleManifest(map, manifestFile);
    } catch (IOException ignored) {
    } catch (InvalidVirtualFileAccessException ignored) {
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) InvalidVirtualFileAccessException(com.intellij.openapi.vfs.InvalidVirtualFileAccessException)

Example 5 with InvalidVirtualFileAccessException

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

the class VirtualDirectoryImpl method getChildren.

@Override
@NotNull
public VirtualFile[] getChildren() {
    if (!isValid()) {
        throw new InvalidVirtualFileAccessException(this);
    }
    NewVirtualFileSystem delegate = getFileSystem();
    final boolean ignoreCase = !delegate.isCaseSensitive();
    synchronized (myData) {
        if (allChildrenLoaded()) {
            assertConsistency(ignoreCase, "");
            return getArraySafely();
        }
        final boolean wasChildrenLoaded = ourPersistence.areChildrenLoaded(this);
        final FSRecords.NameId[] childrenIds = ourPersistence.listAll(this);
        int[] result;
        if (childrenIds.length == 0) {
            result = ArrayUtil.EMPTY_INT_ARRAY;
        } else {
            Arrays.sort(childrenIds, (o1, o2) -> {
                CharSequence name1 = o1.name;
                CharSequence name2 = o2.name;
                int cmp = compareNames(name1, name2, ignoreCase);
                if (cmp == 0 && name1 != name2) {
                    LOG.error(ourPersistence + " returned duplicate file names(" + name1 + "," + name2 + ")" + " ignoreCase: " + ignoreCase + " SystemInfo.isFileSystemCaseSensitive: " + SystemInfo.isFileSystemCaseSensitive + " SystemInfo.OS: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + " wasChildrenLoaded: " + wasChildrenLoaded + " in the dir: " + this + ";" + " children: " + Arrays.toString(childrenIds));
                }
                return cmp;
            });
            TIntHashSet prevChildren = new TIntHashSet(myData.myChildrenIds);
            result = new int[childrenIds.length];
            for (int i = 0; i < childrenIds.length; i++) {
                FSRecords.NameId child = childrenIds[i];
                result[i] = child.id;
                assert child.id > 0 : child;
                prevChildren.remove(child.id);
                if (VfsData.getFileById(child.id, this) == null) {
                    createChild(child.nameId, child.id, delegate);
                }
            }
            if (!prevChildren.isEmpty()) {
                LOG.error("Loaded child disappeared: " + "parent=" + verboseToString.fun(this) + "; child=" + verboseToString.fun(VfsData.getFileById(prevChildren.toArray()[0], this)));
            }
        }
        if (getId() > 0) {
            myData.myChildrenIds = result;
            if (CHECK) {
                assertConsistency(ignoreCase, Arrays.asList(childrenIds));
            }
            setChildrenLoaded();
        }
        return getArraySafely();
    }
}
Also used : FSRecords(com.intellij.openapi.vfs.newvfs.persistent.FSRecords) NewVirtualFileSystem(com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem) InvalidVirtualFileAccessException(com.intellij.openapi.vfs.InvalidVirtualFileAccessException) TIntHashSet(gnu.trove.TIntHashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

InvalidVirtualFileAccessException (com.intellij.openapi.vfs.InvalidVirtualFileAccessException)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 NotNull (org.jetbrains.annotations.NotNull)2 UTF8Properties (aQute.lib.utf8properties.UTF8Properties)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 NewVirtualFileSystem (com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem)1 FSRecords (com.intellij.openapi.vfs.newvfs.persistent.FSRecords)1 SmartList (com.intellij.util.SmartList)1 TIntHashSet (gnu.trove.TIntHashSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Attributes (java.util.jar.Attributes)1 Manifest (java.util.jar.Manifest)1 Nullable (org.jetbrains.annotations.Nullable)1