diff --git a/src/share/classes/java/nio/file/Path.java b/src/share/classes/java/nio/file/Path.java index 618f0226363a530da3e20d809e8c3527048b6544..cefd2d2fd04d29e685f91dd4e462323846bbb3d9 100644 --- a/src/share/classes/java/nio/file/Path.java +++ b/src/share/classes/java/nio/file/Path.java @@ -550,18 +550,21 @@ public interface Path *
If this path is relative then its absolute path is first obtained, * as if by invoking the {@link #toAbsolutePath toAbsolutePath} method. * - *
The {@code resolveLinks} parameter specifies if symbolic links - * should be resolved. This parameter is ignored when symbolic links are - * not supported. Where supported, and the parameter has the value {@code - * true} then symbolic links are resolved to their final target. Where the - * parameter has the value {@code false} then this method does not resolve - * symbolic links. Some implementations allow special names such as - * "{@code ..}" to refer to the parent directory. When deriving the real - * path, and a "{@code ..}" (or equivalent) is preceded by a - * non-"{@code ..}" name then an implementation will typically causes both - * names to be removed. When not resolving symbolic links and the preceding - * name is a symbolic link then the names are only removed if it guaranteed - * that the resulting path will locate the same file as this path. + *
The {@code options} array may be used to indicate how symbolic links
+ * are handled. By default, symbolic links are resolved to their final
+ * target. If the option {@link LinkOption#NOFOLLOW_LINKS NOFOLLOW_LINKS} is
+ * present then this method does not resolve symbolic links.
+ *
+ * Some implementations allow special names such as "{@code ..}" to refer to
+ * the parent directory. When deriving the real path, and a
+ * "{@code ..}" (or equivalent) is preceded by a non-"{@code ..}" name then
+ * an implementation will typically cause both names to be removed. When
+ * not resolving symbolic links and the preceding name is a symbolic link
+ * then the names are only removed if it guaranteed that the resulting path
+ * will locate the same file as this path.
+ *
+ * @param options
+ * options indicating how symbolic links are handled
*
* @return an absolute path represent the real path of the file
* located by this object
@@ -576,7 +579,7 @@ public interface Path
* checkPropertyAccess} method is invoked to check access to the
* system property {@code user.dir}
*/
- Path toRealPath(boolean resolveLinks) throws IOException;
+ Path toRealPath(LinkOption... options) throws IOException;
/**
* Returns a {@link File} object representing this path. Where this {@code
diff --git a/src/share/classes/sun/nio/fs/Util.java b/src/share/classes/sun/nio/fs/Util.java
index 7628701116964fdd8980eb4ee9acfdfd53111bfb..6c94710dd8d68482f05b3ba99849831cbaed9fad 100644
--- a/src/share/classes/sun/nio/fs/Util.java
+++ b/src/share/classes/sun/nio/fs/Util.java
@@ -26,6 +26,7 @@
package sun.nio.fs;
import java.util.*;
+import java.nio.file.*;
/**
* Utility methods
@@ -80,4 +81,21 @@ class Util {
}
return set;
}
+
+ /**
+ * Returns {@code true} if symbolic links should be followed
+ */
+ static boolean followLinks(LinkOption... options) {
+ boolean followLinks = true;
+ for (LinkOption option: options) {
+ if (option == LinkOption.NOFOLLOW_LINKS) {
+ followLinks = false;
+ } else if (option == null) {
+ throw new NullPointerException();
+ } else {
+ throw new AssertionError("Should not get here");
+ }
+ }
+ return followLinks;
+ }
}
diff --git a/src/share/classes/sun/util/calendar/ZoneInfoFile.java b/src/share/classes/sun/util/calendar/ZoneInfoFile.java
index c6251ade5122e4bb6675e26a5ef3f0a33fcb8d29..891817776aaeb72d435b5dcd94ff068f541aae85 100644
--- a/src/share/classes/sun/util/calendar/ZoneInfoFile.java
+++ b/src/share/classes/sun/util/calendar/ZoneInfoFile.java
@@ -479,7 +479,7 @@ public class ZoneInfoFile {
String zi = System.getProperty("java.home") +
File.separator + "lib" + File.separator + "zi";
try {
- zi = FileSystems.getDefault().getPath(zi).toRealPath(true).toString();
+ zi = FileSystems.getDefault().getPath(zi).toRealPath().toString();
} catch(Exception e) {
}
return zi;
diff --git a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java
index d8aa305d29b1ab1be0913966f75656406d3a6a54..530c8864ba61d02ecd6370ef42d53fc9577cf1ae 100644
--- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java
+++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java
@@ -99,7 +99,7 @@ public class ZipFileSystemProvider extends FileSystemProvider {
synchronized(filesystems) {
Path realPath = null;
if (ensureFile(path)) {
- realPath = path.toRealPath(true);
+ realPath = path.toRealPath();
if (filesystems.containsKey(realPath))
throw new FileSystemAlreadyExistsException();
}
@@ -154,7 +154,7 @@ public class ZipFileSystemProvider extends FileSystemProvider {
synchronized (filesystems) {
ZipFileSystem zipfs = null;
try {
- zipfs = filesystems.get(uriToPath(uri).toRealPath(true));
+ zipfs = filesystems.get(uriToPath(uri).toRealPath());
} catch (IOException x) {
// ignore the ioe from toRealPath(), return FSNFE
}
@@ -310,7 +310,7 @@ public class ZipFileSystemProvider extends FileSystemProvider {
//////////////////////////////////////////////////////////////
void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException {
synchronized (filesystems) {
- zfpath = zfpath.toRealPath(true);
+ zfpath = zfpath.toRealPath();
if (filesystems.get(zfpath) == zfs)
filesystems.remove(zfpath);
}
diff --git a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java
index 1232a27ff1f0b2c1f0d1cb9d6307854a5e22e630..8c97818b24482f3fde4f129a7f46185054d041e7 100644
--- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java
+++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipPath.java
@@ -150,7 +150,7 @@ public class ZipPath implements Path {
}
@Override
- public ZipPath toRealPath(boolean resolveLinks) throws IOException {
+ public ZipPath toRealPath(LinkOption... options) throws IOException {
ZipPath realPath = new ZipPath(zfs, getResolvedPath()).toAbsolutePath();
realPath.checkAccess();
return realPath;
diff --git a/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java
index 6659ff5ede48f5871524e7697db056d53b87df54..0b8aa14e1882b1a57f43561dc716c9e16c59a795 100644
--- a/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java
+++ b/src/solaris/classes/sun/nio/fs/LinuxFileSystemProvider.java
@@ -56,11 +56,11 @@ public class LinuxFileSystemProvider extends UnixFileSystemProvider {
{
if (type == DosFileAttributeView.class) {
return (V) new LinuxDosFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
}
if (type == UserDefinedFileAttributeView.class) {
return (V) new LinuxUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
}
return super.getFileAttributeView(obj, type, options);
}
@@ -72,11 +72,11 @@ public class LinuxFileSystemProvider extends UnixFileSystemProvider {
{
if (name.equals("dos")) {
return new LinuxDosFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
}
if (name.equals("user")) {
return new LinuxUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
}
return super.getFileAttributeView(obj, name, options);
}
diff --git a/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java
index 98c3ae8699ca580bf37a26b26a7e763f649be1e9..eca619be1d0dfbe21cdd84aa674eda8d58b05361 100644
--- a/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java
+++ b/src/solaris/classes/sun/nio/fs/SolarisFileSystemProvider.java
@@ -57,11 +57,11 @@ public class SolarisFileSystemProvider extends UnixFileSystemProvider {
{
if (type == AclFileAttributeView.class) {
return (V) new SolarisAclFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
}
if (type == UserDefinedFileAttributeView.class) {
return(V) new SolarisUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
}
return super.getFileAttributeView(obj, type, options);
}
@@ -73,10 +73,10 @@ public class SolarisFileSystemProvider extends UnixFileSystemProvider {
{
if (name.equals("acl"))
return new SolarisAclFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
if (name.equals("user"))
return new SolarisUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
- followLinks(options));
+ Util.followLinks(options));
return super.getFileAttributeView(obj, name, options);
}
}
diff --git a/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java
index 8ec672a306bbca65911ae715730de5aa6effeff5..1bee2d0b3860e3d60477ef52b9427c1bb5d0630b 100644
--- a/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java
+++ b/src/solaris/classes/sun/nio/fs/UnixFileSystemProvider.java
@@ -105,20 +105,6 @@ public abstract class UnixFileSystemProvider
return (UnixPath)obj;
}
- boolean followLinks(LinkOption... options) {
- boolean followLinks = true;
- for (LinkOption option: options) {
- if (option == LinkOption.NOFOLLOW_LINKS) {
- followLinks = false;
- continue;
- }
- if (option == null)
- throw new NullPointerException();
- throw new AssertionError("Should not get here");
- }
- return followLinks;
- }
-
@Override
@SuppressWarnings("unchecked")
public