You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/20 13:57:01 UTC
svn commit: r766665 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/io/File.java native/include/acr_error.h
native/os/unix/file.c native/shared/error.c
Author: mturk
Date: Mon Apr 20 11:57:01 2009
New Revision: 766665
URL: http://svn.apache.org/viewvc?rev=766665&view=rev
Log:
Add SecurityException for EACCES
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=766665&r1=766664&r2=766665&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Mon Apr 20 11:57:01 2009
@@ -32,11 +32,11 @@
// Native methods from libacr.
private static native int ftype0(String pathname)
- throws IOException;
+ throws IOException, SecurityException;
private static native boolean mkslink0(String target, String link)
- throws IOException;
+ throws IOException, SecurityException;
private static native String target0(String link)
- throws IOException;
+ throws IOException, SecurityException;
// Catched FileType Enum integer value.
private int fileType = -1;
@@ -158,10 +158,12 @@
*
* @return {@link FileType} representing the type of the file.
* @throws IOException If an I/O error occured.
+ * @throws SecurityException If Search permission is denied for one of
+ * the directories in the path prefix this {@code File} path.
* @see FileType
*/
public FileType getFileType()
- throws IOException
+ throws IOException, SecurityException
{
// We could catch the IOException here and rethrow again
// to hide the 'Native Method' in Stack trace.
@@ -176,10 +178,12 @@
*
* @return {@code true} if the file is symbolic link.
* @throws IOException If an I/O error occured.
+ * @throws SecurityException If Search permission is denied for one of
+ * the directories in the path prefix this {@code File} path.
* @see FileType
*/
public boolean isSymbolicLink()
- throws IOException
+ throws IOException, SecurityException
{
if (fileType < 0)
fileType = ftype0(getPath());
@@ -212,9 +216,12 @@
* @return {@code true} if symbolic link was created, false if it already
* exists.
* @throws IOException in case of error.
+ * @throws SecurityException if Write access to the directory containing
+ * {@code link} is denied, or one of the directories in the
+ * path prefix of {@code link} did not allow search permission.
*/
public static boolean createSymbolicLink(String target, String link)
- throws IOException
+ throws IOException, SecurityException
{
return mkslink0(target, link);
}
@@ -241,11 +248,14 @@
*
* @param link The symbolic link name.
* @return New {@code File} instance containing symbolic link to this
- * file instance.
+ * file instance.
* @throws IOException in case of error.
+ * @throws SecurityException if Write access to the directory containing
+ * {@code link} is denied, or one of the directories in the
+ * path prefix of {@code link} did not allow search permission.
*/
public File createSymbolicLink(String link)
- throws IOException
+ throws IOException, SecurityException
{
// False means EEXIST, so just consider it opened
// Check is made wather it points to the same target
@@ -258,29 +268,33 @@
}
}
- /**
+ /**
* Return target pathname of this abstract {@code File} instance.
*
* @return Pathname this {@code File} points to.
* @throws IOException if this {@code File} is not symbolic link
* or an I/O error occured.
- */
+ * @throws SecurityException if search permission is denied for a
+ * component of this abstract {@code File} pathname prefix.
+ */
public String getTargetPath()
- throws IOException
+ throws IOException, SecurityException
{
return target0(getPath());
}
- /**
+ /**
* Return new abstract {@code File} target instance of this
* abstract {@code File} instance.
*
* @return New {@code File} instance this {@code File} points to.
* @throws IOException if this {@code File} is not symbolic link
* or an I/O error occured.
- */
+ * @throws SecurityException if search permission is denied for a
+ * component of this abstract {@code File} pathname prefix.
+ */
public File getTargetFile()
- throws IOException
+ throws IOException, SecurityException
{
return new File(getTargetPath());
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=766665&r1=766664&r2=766665&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Mon Apr 20 11:57:01 2009
@@ -46,9 +46,12 @@
ACR_EX_ECCAST, /* java/lang/ClassCastException */
ACR_EX_EINSTANCE, /* java/lang/InstatntiationException */
ACR_EX_EINTERNAL, /* java/lang/InternalError */
+ ACR_EX_ESECURITY, /* java/lang/SecurityException */
+ ACR_EX_ENOTIMPL, /* java/lang/UnsupportedOperationException */
ACR_EX_EIO, /* java/io/IOException */
ACR_EX_ESYNC, /* java/io/SyncFailedException */
- ACR_EX_ESOCK /* java/net/SocketException */
+ ACR_EX_ESOCK, /* java/net/SocketException */
+ ACR_EX_LEN
} acr_trowclass_e;
/*
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=766665&r1=766664&r2=766665&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Mon Apr 20 11:57:01 2009
@@ -101,7 +101,10 @@
* include the operating system you are using.
*/
#endif
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, errno);
+ if (errno == EACCES)
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, errno);
}
return -1;
}
@@ -128,9 +131,10 @@
WITH_CSTR(target) {
WITH_CSTR(lnkname) {
if (symlink(J2S(target), J2S(lnkname))) {
- int err = ACR_GET_OS_ERROR();
- if (err != EEXIST) {
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, err);
+ if (errno == EACCES)
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else if (errno != EEXIST) {
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, errno);
}
}
else
@@ -153,8 +157,10 @@
rd = readlink(J2S(lnkname), buf, PATH_MAX - 1);
if (rd < 0) {
- int err = ACR_GET_OS_ERROR();
- ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, err);
+ if (errno == EACCES)
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+ else
+ ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, errno);
}
else {
buf[rd] = '\0';
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=766665&r1=766664&r2=766665&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Mon Apr 20 11:57:01 2009
@@ -32,6 +32,8 @@
"java/lang/ClassCastException",
"java/lang/InstatntiationException",
"java/lang/InternalError",
+ "java/lang/SecurityException",
+ "java/lang/UnsupportedOperationException",
"java/io/IOException",
"java/io/SyncFailedException",
"java/net/SocketException",
@@ -99,7 +101,7 @@
ACR_DECLARE(void) ACR_ThrowExceptionA(JNIEnv *env,
const char *file, int line,
acr_trowclass_e clazz, const char *msg)
-{
+{
ACR_ThrowClassEx(env, file, line, throw_classes[clazz], msg);
}