Use Files.isSymbolicLink on non-Windows platforms
@@ -60,13 +60,10 @@ import java.nio.file.FileSystemException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
-import java.nio.file.LinkOption;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.DosFileAttributes;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.DigestInputStream;
import java.security.MessageDigest;
@@ -295,6 +292,7 @@ public class Util {
@Restricted(NoExternalUse.class)
public static boolean isSymlink(@Nonnull Path path) {
+ if (Functions.isWindows()) {
/*
* Windows Directory Junctions are effectively the same as Linux symlinks to directories.
* Unfortunately, the Java 7 NIO2 API function isSymbolicLink does not treat them as such.
@@ -309,11 +307,14 @@ public class Util {
*/
try {
return path.compareTo(path.toRealPath()) != 0;
- } catch (NoSuchFileException e) {
+ } catch (NoSuchFileException ignored) {
return false;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
+ } else {
+ return Files.isSymbolicLink(path);
+ }
}
/**
