Skip to content

Commit 7f2f38b

Browse files
HannesWelliloveeclipse
authored andcommitted
Avoid duplicated read of file attributes in ExternalFoldersManager
in case the tested path is a directory.
1 parent 6a6c5d2 commit 7f2f38b

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ExternalFoldersManager.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
*******************************************************************************/
1818
package org.eclipse.jdt.internal.core;
1919

20-
import java.io.File;
2120
import java.io.FileOutputStream;
2221
import java.io.IOException;
2322
import java.nio.file.Files;
23+
import java.nio.file.attribute.BasicFileAttributes;
2424
import java.util.ArrayList;
2525
import java.util.Collection;
2626
import java.util.Collections;
@@ -151,12 +151,16 @@ public static boolean isExternalFolderPath(IPath externalPath) {
151151
return false;
152152
}
153153
// Test if this an absolute path in local file system (not the workspace path)
154-
File externalFolder = externalPath.toFile();
155-
if (Files.isRegularFile(externalFolder.toPath())) {
154+
BasicFileAttributes externalAttributes = null;
155+
try {
156+
externalAttributes = Files.readAttributes(externalPath.toPath(), BasicFileAttributes.class);
157+
} catch (IOException e) { // assume not existing
158+
}
159+
if (externalAttributes != null && externalAttributes.isRegularFile()) {
156160
manager.addExternalFile(externalPath, true);
157161
return false;
158162
}
159-
if (Files.isDirectory(externalFolder.toPath())) {
163+
if (externalAttributes != null && externalAttributes.isDirectory()) {
160164
return true;
161165
}
162166
// this can be now only full workspace path or an external path to a not existing file or folder

0 commit comments

Comments
 (0)