Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2021-02-06 16:18:33 +0000
committerLars Vogel2021-09-10 08:06:54 +0000
commit7c4abd208b2ab780f54d945015d3e2c36281cf24 (patch)
tree88037cd3b93e5a1fd21f32f207bdedff9ed3e186
parentc09b8f6d9a9cccffeffea771ae9fbde333d38262 (diff)
downloadeclipse.platform.resources-7c4abd208b2ab780f54d945015d3e2c36281cf24.tar.gz
eclipse.platform.resources-7c4abd208b2ab780f54d945015d3e2c36281cf24.tar.xz
eclipse.platform.resources-7c4abd208b2ab780f54d945015d3e2c36281cf24.zip
Bug 572338 - use only one file access instead of 4 to collect fileI20210911-1800I20210910-1800
information Change-Id: I14df62244b0cbcfc782e4bb17e0b25d4e3468d24 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.resources/+/175921 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Karsten Thoms <karsten.thoms@karakun.com> Reviewed-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r--bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/nio/DefaultHandler.java55
1 files changed, 28 insertions, 27 deletions
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/nio/DefaultHandler.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/nio/DefaultHandler.java
index f47da5f2c..a9de93ad8 100644
--- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/nio/DefaultHandler.java
+++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/nio/DefaultHandler.java
@@ -18,6 +18,7 @@ package org.eclipse.core.internal.filesystem.local.nio;
import java.io.File;
import java.io.IOException;
import java.nio.file.*;
+import java.nio.file.attribute.BasicFileAttributes;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.provider.FileInfo;
@@ -35,40 +36,40 @@ public class DefaultHandler extends NativeHandler {
@Override
public FileInfo fetchFileInfo(String fileName) {
Path path = Paths.get(fileName);
- boolean exists = Files.exists(path);
-
FileInfo info = new FileInfo();
+ boolean exists = Files.exists(path);
info.setExists(exists);
- // Even if it doesn't exist then check for symbolic link information.
- boolean isSymbolicLink = Files.isSymbolicLink(path);
- if (isSymbolicLink) {
- info.setAttribute(EFS.ATTRIBUTE_SYMLINK, true);
- try {
- info.setStringAttribute(EFS.ATTRIBUTE_LINK_TARGET, Files.readSymbolicLink(path).toString());
- } catch (IOException e) {
- // Leave the target alone.
- info.setError(IFileInfo.IO_ERROR);
+ try {
+ BasicFileAttributes readAttributes = Files.readAttributes(path, BasicFileAttributes.class);
+
+ // Even if it doesn't exist then check for symbolic link information.
+ if (readAttributes.isSymbolicLink()) {
+ info.setAttribute(EFS.ATTRIBUTE_SYMLINK, true);
+ try {
+ info.setStringAttribute(EFS.ATTRIBUTE_LINK_TARGET, Files.readSymbolicLink(path).toString());
+ } catch (IOException e) {
+ // Leave the target alone.
+ info.setError(IFileInfo.IO_ERROR);
+ }
}
- }
- // Fill in the name of the file.
- // If the file system is case insensitive, we don't know the real name of the file.
- // Since obtaining the real name in such situation is pretty expensive, we use the name
- // passed as a parameter, which may differ by case from the real name of the file
- // if the file system is case insensitive.
- info.setName(path.toFile().getName());
+ // Fill in the name of the file.
+ // If the file system is case insensitive, we don't know the real name of the file.
+ // Since obtaining the real name in such situation is pretty expensive, we use the name
+ // passed as a parameter, which may differ by case from the real name of the file
+ // if the file system is case insensitive.
+ info.setName(path.toFile().getName());
- // Since we will be using a mixture of pre Java 7 API's which do not support the
- // retrieval of information for the symbolic link itself instead of the target
- // we will only support the following details if the symbolic link target exists.
- if (!exists)
- return info;
+ // Since we will be using a mixture of pre Java 7 API's which do not support the
+ // retrieval of information for the symbolic link itself instead of the target
+ // we will only support the following details if the symbolic link target exists.
+ if (!exists)
+ return info;
- try {
- info.setLastModified(Files.getLastModifiedTime(path).toMillis());
- info.setLength(Files.size(path));
- info.setDirectory(Files.isDirectory(path));
+ info.setLastModified(readAttributes.lastModifiedTime().toMillis());
+ info.setLength(readAttributes.size());
+ info.setDirectory(readAttributes.isDirectory());
info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, !Files.isWritable(path) && Files.isReadable(path));
info.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, Files.isExecutable(path));

Back to the top