mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Do not index and navigate to broken links
This commit is contained in:
@@ -261,6 +261,17 @@ public class VfsUtilCore {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if given virtual file represents broken symbolic link (which points to non-existent file).
|
||||
*/
|
||||
public static boolean isBrokenLink(@NotNull VirtualFile link) {
|
||||
final VirtualFile target = link.getCanonicalFile();
|
||||
return target == null || target.equals(link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if given virtual file represents broken or recursive symbolic link.
|
||||
*/
|
||||
public static boolean isInvalidLink(@NotNull VirtualFile link) {
|
||||
final VirtualFile target = link.getCanonicalFile();
|
||||
return target == null || target.equals(link) || isAncestor(target, link, true);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.pom.PomTargetPsiElement;
|
||||
@@ -29,8 +30,7 @@ import com.intellij.psi.util.PsiUtilCore;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EditSourceUtil {
|
||||
private EditSourceUtil() {
|
||||
}
|
||||
private EditSourceUtil() { }
|
||||
|
||||
@Nullable
|
||||
public static Navigatable getDescriptor(final PsiElement element) {
|
||||
@@ -58,9 +58,9 @@ public class EditSourceUtil {
|
||||
if (element == null || !element.isValid()) {
|
||||
return false;
|
||||
}
|
||||
final PsiElement navigationElement = element.getNavigationElement();
|
||||
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
|
||||
return virtualFile != null && virtualFile.isValid() && !virtualFile.isSpecialFile();
|
||||
|
||||
VirtualFile file = PsiUtilCore.getVirtualFile(element.getNavigationElement());
|
||||
return file != null && file.isValid() && !file.isSpecialFile() && !VfsUtilCore.isBrokenLink(file);
|
||||
}
|
||||
|
||||
public static void navigate(NavigationItem item, boolean requestFocus, boolean useCurrentWindow) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.vfs.InvalidVirtualFileAccessException;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -55,9 +56,7 @@ public class FileContentQueue {
|
||||
public void run() {
|
||||
try {
|
||||
for (VirtualFile file : files) {
|
||||
if (indicator != null) {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
indicator.checkCanceled();
|
||||
addLast(file, indicator);
|
||||
}
|
||||
|
||||
@@ -87,7 +86,7 @@ public class FileContentQueue {
|
||||
private void addLast(VirtualFile file, @NotNull final ProgressIndicator indicator) throws InterruptedException {
|
||||
FileContent content = new FileContent(file);
|
||||
|
||||
if (file.isValid() && !file.isDirectory()) {
|
||||
if (file.isValid() && !file.isDirectory() && !file.isSpecialFile() && !VfsUtilCore.isBrokenLink(file)) {
|
||||
if (!doLoadContent(content, indicator)) {
|
||||
content.setEmptyContent();
|
||||
}
|
||||
@@ -99,6 +98,7 @@ public class FileContentQueue {
|
||||
myQueue.put(content);
|
||||
}
|
||||
|
||||
@SuppressWarnings("InstanceofCatchParameter")
|
||||
private boolean doLoadContent(final FileContent content, @NotNull final ProgressIndicator indicator) throws InterruptedException {
|
||||
final long contentLength = content.getLength();
|
||||
|
||||
@@ -124,10 +124,16 @@ public class FileContentQueue {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
if (e instanceof ProcessCanceledException) throw (ProcessCanceledException)e;
|
||||
if (e instanceof InterruptedException) throw (InterruptedException)e;
|
||||
|
||||
if (e instanceof IOException || e instanceof InvalidVirtualFileAccessException) LOG.info(e);
|
||||
if (e instanceof ProcessCanceledException) {
|
||||
throw (ProcessCanceledException)e;
|
||||
}
|
||||
else if (e instanceof InterruptedException) {
|
||||
throw (InterruptedException)e;
|
||||
}
|
||||
else if (e instanceof IOException || e instanceof InvalidVirtualFileAccessException) {
|
||||
LOG.info(e);
|
||||
}
|
||||
else if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user