From 71e16df447dae5a880b2d28985bd701f7bfb3134 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Fri, 12 Mar 2010 20:21:53 +0300 Subject: [PATCH] CacheUpdate: invalid file access handling --- .../openapi/project/FileContentQueue.java | 92 +++++++++---------- 1 file changed, 43 insertions(+), 49 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java b/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java index a8f3a6d48633..fd508a67f21b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/FileContentQueue.java @@ -21,6 +21,8 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.util.Computable; +import com.intellij.openapi.vfs.InvalidVirtualFileAccessException; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS; import org.jetbrains.annotations.NotNull; @@ -74,60 +76,12 @@ public class FileContentQueue { } private void put(VirtualFile file) throws InterruptedException { - final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); - FileContent content = new FileContent(file); if (file.isValid()) { - final long contentLength = content.getLength(); - boolean counterUpdated = false; - try { - if (contentLength < PersistentFS.MAX_INTELLISENSE_FILESIZE) { - synchronized (this) { - while (myTotalSize > SIZE_THRESHOLD) { - if (indicator != null) { - indicator.checkCanceled(); - } - wait(300); - } - myTotalSize += contentLength; - counterUpdated = true; - } - - content.getBytes(); // Reads the content bytes and caches them. - } - } - catch (IOException e) { - LOG.info(e); - if (counterUpdated) { - synchronized (this) { - myTotalSize -= contentLength; // revert size counter - notifyAll(); - } - } + if (!doLoadContent(content)) { content.setEmptyContent(); } - catch (ProcessCanceledException e) { - if (counterUpdated) { - synchronized (this) { - myTotalSize -= contentLength; // revert size counter - notifyAll(); - } - } - throw e; - } - catch (InterruptedException e) { - if (counterUpdated) { - synchronized (this) { - myTotalSize -= contentLength; // revert size counter - notifyAll(); - } - } - return; - } - catch (Throwable e) { - LOG.error(e); - } } else { content.setEmptyContent(); @@ -136,6 +90,46 @@ public class FileContentQueue { myQueue.put(content); } + private boolean doLoadContent(final FileContent content) throws InterruptedException { + final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator(); + final long contentLength = content.getLength(); + + boolean counterUpdated = false; + try { + if (contentLength < PersistentFS.MAX_INTELLISENSE_FILESIZE) { + synchronized (this) { + while (myTotalSize > SIZE_THRESHOLD) { + if (indicator != null) { + indicator.checkCanceled(); + } + wait(300); + } + myTotalSize += contentLength; + counterUpdated = true; + } + + content.getBytes(); // Reads the content bytes and caches them. + } + + return true; + } + catch (Throwable e) { + if (counterUpdated) { + synchronized (this) { + myTotalSize -= contentLength; // revert size counter + 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); + else LOG.error(e); + + return false; + } + } + public FileContent take() { FileContent result; synchronized (this) { -- 2.32.0