diff options
author | Thomas Watson | 2020-10-30 19:16:20 +0000 |
---|---|---|
committer | Thomas Watson | 2020-10-30 19:16:47 +0000 |
commit | 11fa29c9a6e86962b9414dca448b87f929228653 (patch) | |
tree | 82a56453f9b236f4eb6200de9910ae84688f9bd7 | |
parent | 5f935ae7f99c9cfac59a3f4af55bbd0da26a7238 (diff) | |
download | rt.equinox.framework-11fa29c9a6e86962b9414dca448b87f929228653.tar.gz rt.equinox.framework-11fa29c9a6e86962b9414dca448b87f929228653.tar.xz rt.equinox.framework-11fa29c9a6e86962b9414dca448b87f929228653.zip |
Bug 567964 - Use Files.isReadable before falling back to File IOY20201201-1200Y20201127-1200Y20201124-1200Y20201120-1200Y20201117-1200Y20201113-1200Y20201111-0210Y20201110-1200Y20201109-1200Y20201109-0220Y20201108-1200Y20201107-1200Y20201106-1200Y20201105-1200Y20201104-1200Y20201103-1200Y20201102-1200Y20201101-1200Y20201031-1200S4_18_0_RC2S4_18_0_RC1S4_18_0_M3R4_18I20210122-0800I20210122-0630I20210122-0420I20201202-1800I20201202-0600I20201201-1800I20201201-0600I20201130-1800I20201130-0600I20201129-1800I20201129-0600I20201128-1800I20201128-0600I20201128-0300I20201127-1800I20201127-1010I20201127-0630I20201125-1800I20201125-0600I20201124-1800I20201124-0600I20201123-1800I20201123-0600I20201122-1800I20201122-0600I20201121-1800I20201121-0600I20201120-1800I20201120-0320I20201119-0730I20201118-1800I20201118-0600I20201117-1800I20201117-0600I20201116-1800I20201116-0600I20201115-1800I20201115-0600I20201114-1800I20201114-0740I20201114-0600I20201113-1800I20201112-1800I20201111-1800I20201110-1800I20201109-1800I20201108-1800I20201107-1800I20201107-0750I20201106-1800I20201106-0710I20201105-1800I20201105-0230I20201104-1800I20201103-1800I20201103-0030I20201102-1910I20201101-1800I20201031-1800I20201030-1800R4_18_maintenance
Some environments it is more costly to do the file open/close operation
than simply calling Files.isReadable. First try Files.isReadable for
the golden path, if that fails then fallback to the previous behavior
Change-Id: I7aaf92c4d3d1a599343034078ebb214a8da7a305
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r-- | bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java index d6b653f55..08de673ad 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; +import java.nio.file.Files; import org.eclipse.osgi.framework.util.FilePath; import org.eclipse.osgi.internal.location.LocationHelper; import org.eclipse.osgi.internal.messages.Msg; @@ -69,26 +70,30 @@ public class ReferenceURLConnection extends URLConnection { private void checkRead(File file) throws IOException { if (!file.exists()) throw new FileNotFoundException(file.toString()); - if (file.isFile()) { - // Try to open the file to ensure that this is possible: see bug 260217 - // If access is denied, a FileNotFoundException with (access denied) message is thrown - // Here file.canRead() cannot be used, because on Windows it does not - // return correct values - bug 6203387 in Sun's bug database - InputStream is = new FileInputStream(file); - is.close(); - } else if (file.isDirectory()) { - // There is no straightforward way to check if a directory - // has read permissions - same issues for File.canRead() as above; - // try to list the files in the directory - File[] files = file.listFiles(); - // File.listFiles() returns null if the directory does not exist - // (which is not the current case, because we check that it exists and is directory), - // or if an IO error occurred during the listing of the files, including if the - // access is denied - if (files == null) - throw new FileNotFoundException(file.toString() + " (probably access denied)"); //$NON-NLS-1$ - } else { - // TODO not sure if we can get here. + if (!Files.isReadable(file.toPath())) { + if (file.isFile()) { + // Try to open the file to ensure that this is possible: see bug 260217 + // If access is denied, a FileNotFoundException with (access denied) message is + // thrown + // Here file.canRead() cannot be used, because on Windows it does not + // return correct values - bug 6203387 in Sun's bug database + InputStream is = new FileInputStream(file); + is.close(); + } else if (file.isDirectory()) { + // There is no straightforward way to check if a directory + // has read permissions - same issues for File.canRead() as above; + // try to list the files in the directory + File[] files = file.listFiles(); + // File.listFiles() returns null if the directory does not exist + // (which is not the current case, because we check that it exists and is + // directory), + // or if an IO error occurred during the listing of the files, including if the + // access is denied + if (files == null) + throw new FileNotFoundException(file.toString() + " (probably access denied)"); //$NON-NLS-1$ + } else { + // TODO not sure if we can get here. + } } } |