Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileSystem] Simplify and modernize NativeHandlers #1441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
Expand All @@ -35,13 +37,12 @@ public class DefaultHandler extends NativeHandler {

@Override
public FileInfo fetchFileInfo(String fileName) {
Path path = Paths.get(fileName);
Path path = Path.of(fileName);
FileInfo info = new FileInfo();
boolean exists = Files.exists(path);
info.setExists(exists);

try {
BasicFileAttributes readAttributes = Files.readAttributes(path, BasicFileAttributes.class);
info.setExists(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a junit test if this behaves like before for hidden files as the code contains comments that opening hidden files can lead to FileNotFoundException. See uses of org.eclipse.core.filesystem.EFS.ATTRIBUTE_HIDDEN

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can look at https://github.com/eclipse-platform/eclipse.platform/pull/1444/files#diff-81300c5bdd85b0fca987936ae34590fbf4bbf835119e1efd68698461d230b817R252 how to create a hidden file.
But to me it is not clear how/if the Defaulthandler is tested in CI


// Even if it doesn't exist then check for symbolic link information.
if (readAttributes.isSymbolicLink()) {
Expand All @@ -59,20 +60,21 @@ public FileInfo fetchFileInfo(String fileName) {
// 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());
info.setName(path.getFileName().toString());

// 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;

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));

} catch (NoSuchFileException e) {
// file does not exist, which is valid. Continue, FileInfo.exists is false by default.
} catch (IOException e) {
// Leave alone and continue.
info.setError(IFileInfo.IO_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.DosFileAttributes;
import org.eclipse.core.filesystem.EFS;
Expand All @@ -39,7 +42,7 @@ public FileInfo fetchFileInfo(String fileName) {
FileInfo info = new FileInfo();

try {
Path path = Paths.get(fileName);
Path path = Path.of(fileName);

// Use canonical file to get the correct case of filename. See bug 431983.
Path fileNamePath = path.toRealPath(LinkOption.NOFOLLOW_LINKS).getFileName();
Expand Down Expand Up @@ -91,7 +94,7 @@ public int getSupportedAttributes() {

@Override
public boolean putFileInfo(String fileName, IFileInfo info, int options) {
Path path = Paths.get(fileName);
Path path = Path.of(fileName);
// To be consistent with fetchInfo do not following symbolic links to set archive, read only and hidden attributes.
DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
package org.eclipse.core.internal.filesystem.local.nio;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.filesystem.EFS;
Expand All @@ -38,7 +43,7 @@ public class PosixHandler extends NativeHandler {

@Override
public FileInfo fetchFileInfo(String fileName) {
Path path = Paths.get(fileName);
Path path = Path.of(fileName);
FileInfo info = new FileInfo();

// Fill in the name of the file.
Expand Down Expand Up @@ -89,7 +94,7 @@ public int getSupportedAttributes() {

@Override
public boolean putFileInfo(String fileName, IFileInfo info, int options) {
Path path = Paths.get(fileName);
Path path = Path.of(fileName);
Set<PosixFilePermission> perms = new HashSet<>();

if (info.getAttribute(EFS.ATTRIBUTE_OWNER_READ))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void assumeSymbolicLinksAvailable() throws Exception {
FileSystemHelper.canCreateSymLinks());
}

// TODO: test hard-links too?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove todo


protected void fetchFileInfos() {
iDir = aDir.fetchInfo();
iFile = aFile.fetchInfo();
Expand Down
Loading