Skip to content

Commit 9fa486f

Browse files
EcljpseB0Tjukzi
authored andcommitted
[performance] Avoid 2nd file access on lightweightAutoRefresh #1442
When reading file content with force==true it is tried to read that file from file system. Only if the read fails the existence of that file can have changed and exception is thrown anyway. We just need to move the "asyncRefresh" into the exception handler. Hotspot from JDTs ResourceCompilationUnit.getContents() fixes #1442 tested by Bug_303517
1 parent b167443 commit 9fa486f

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ public InputStream read(IFile target, boolean force, IProgressMonitor monitor) t
874874
try {
875875
return store.openInputStream(EFS.NONE, monitor);
876876
} catch (CoreException e) {
877+
asyncRefresh(target);
877878
if (e.getStatus().getCode() == EFS.ERROR_NOT_EXISTS) {
878879
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString());
879880
throw new ResourceException(IResourceStatus.RESOURCE_NOT_FOUND, target.getFullPath(), message, e);
@@ -884,23 +885,14 @@ public InputStream read(IFile target, boolean force, IProgressMonitor monitor) t
884885

885886
private IFileStore getFileStore(IFile target, boolean force) throws ResourceException, CoreException {
886887
IFileStore store = getStore(target);
887-
if (lightweightAutoRefreshEnabled || !force) {
888+
if (!force) {
888889
final IFileInfo fileInfo = store.fetchInfo();
889-
if (!fileInfo.exists()) {
890-
asyncRefresh(target);
891-
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString());
892-
throw new ResourceException(IResourceStatus.RESOURCE_NOT_FOUND, target.getFullPath(), message, null);
893-
}
894890
Resource resource = (Resource) target;
895891
ResourceInfo info = resource.getResourceInfo(true, false);
896-
int flags = resource.getFlags(info);
897-
resource.checkExists(flags, true);
898892
if (fileInfo.getLastModified() != info.getLocalSyncInfo()) {
899893
asyncRefresh(target);
900-
if (!force) {
901-
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
902-
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null);
903-
}
894+
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
895+
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null);
904896
}
905897
}
906898
return store;
@@ -912,6 +904,7 @@ public byte[] readAllBytes(IFile target, boolean force, IProgressMonitor monitor
912904
try {
913905
return store.readAllBytes(EFS.NONE, monitor);
914906
} catch (CoreException e) {
907+
asyncRefresh(target);
915908
if (e.getStatus().getCode() == EFS.ERROR_NOT_EXISTS) {
916909
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString());
917910
throw new ResourceException(IResourceStatus.RESOURCE_NOT_FOUND, target.getFullPath(), message, e);

0 commit comments

Comments
 (0)