summaryrefslogtreecommitdiff
path: root/src/java
diff options
context:
space:
mode:
authorNoah Watkins <noahwatkins@gmail.com>2012-11-20 13:44:47 -0800
committerNoah Watkins <noahwatkins@gmail.com>2012-11-20 13:55:32 -0800
commit436baa0b47da2e31a3e7e82b2111942b88d73ebd (patch)
tree9f68f8f81e719b150923653724a79a4ec72c2356 /src/java
parent48295a188f8c12cfe8a172b598b96c88ec2e7089 (diff)
downloadceph-436baa0b47da2e31a3e7e82b2111942b88d73ebd.tar.gz
java: add Java exception for ENOTDIR
This specialization is useful in the Hadoop CephFS shim. An lstat may return ENOTENT or ENOTDIR or some other IOException without a specialization. In Hadoop we convert ENOTDIR into ENOENT. Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
Diffstat (limited to 'src/java')
-rw-r--r--src/java/Makefile.am3
-rw-r--r--src/java/java/com/ceph/fs/CephMount.java2
-rw-r--r--src/java/java/com/ceph/fs/CephNotDirectoryException.java42
-rw-r--r--src/java/native/libcephfs_jni.cc9
-rw-r--r--src/java/test/com/ceph/fs/CephMountTest.java14
5 files changed, 68 insertions, 2 deletions
diff --git a/src/java/Makefile.am b/src/java/Makefile.am
index f64129f1c3d..55ff6c170df 100644
--- a/src/java/Makefile.am
+++ b/src/java/Makefile.am
@@ -7,7 +7,8 @@ JAVA_SRC = \
java/com/ceph/fs/CephNativeLoader.java \
java/com/ceph/fs/CephNotMountedException.java \
java/com/ceph/fs/CephFileAlreadyExistsException.java \
- java/com/ceph/fs/CephAlreadyMountedException.java
+ java/com/ceph/fs/CephAlreadyMountedException.java \
+ java/com/ceph/fs/CephNotDirectoryException.java
JAVA_TEST_SRC = \
test/com/ceph/fs/CephDoubleMountTest.java \
diff --git a/src/java/java/com/ceph/fs/CephMount.java b/src/java/java/com/ceph/fs/CephMount.java
index a30961f9245..d814804b92a 100644
--- a/src/java/java/com/ceph/fs/CephMount.java
+++ b/src/java/java/com/ceph/fs/CephMount.java
@@ -338,7 +338,7 @@ public class CephMount {
* @param path Path of file to stat.
* @param stat CephStat structure to hold file status.
*/
- public void lstat(String path, CephStat stat) throws FileNotFoundException {
+ public void lstat(String path, CephStat stat) throws FileNotFoundException, CephNotDirectoryException {
native_ceph_lstat(instance_ptr, path, stat);
}
diff --git a/src/java/java/com/ceph/fs/CephNotDirectoryException.java b/src/java/java/com/ceph/fs/CephNotDirectoryException.java
new file mode 100644
index 00000000000..5181cb9c7a4
--- /dev/null
+++ b/src/java/java/com/ceph/fs/CephNotDirectoryException.java
@@ -0,0 +1,42 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+package com.ceph.fs;
+
+import java.io.IOException;
+
+/**
+ * Component of path is not a directory.
+ */
+public class CephNotDirectoryException extends IOException {
+
+ /**
+ * Construct CephNotDirectoryException.
+ */
+ public CephNotDirectoryException() {
+ super();
+ }
+
+ /**
+ * Construct CephNotDirectoryException with message.
+ */
+ public CephNotDirectoryException(String s) {
+ super(s);
+ }
+}
diff --git a/src/java/native/libcephfs_jni.cc b/src/java/native/libcephfs_jni.cc
index b8fdd01e1cc..13132900d16 100644
--- a/src/java/native/libcephfs_jni.cc
+++ b/src/java/native/libcephfs_jni.cc
@@ -38,6 +38,7 @@
#define CEPH_NOTMOUNTED_CP "com/ceph/fs/CephNotMountedException"
#define CEPH_FILEEXISTS_CP "com/ceph/fs/CephFileAlreadyExistsException"
#define CEPH_ALREADYMOUNTED_CP "com/ceph/fs/CephAlreadyMountedException"
+#define CEPH_NOTDIR_CP "com/ceph/fs/CephNotDirectoryException"
/*
* Flags to open(). must be synchronized with CephMount.java
@@ -200,6 +201,11 @@ static void cephThrowFileExists(JNIEnv *env, const char *msg)
THROW(env, CEPH_FILEEXISTS_CP, msg);
}
+static void cephThrowNotDir(JNIEnv *env, const char *msg)
+{
+ THROW(env, CEPH_NOTDIR_CP, msg);
+}
+
static void handle_error(JNIEnv *env, int rc)
{
switch (rc) {
@@ -209,6 +215,9 @@ static void handle_error(JNIEnv *env, int rc)
case -EEXIST:
cephThrowFileExists(env, "");
return;
+ case -ENOTDIR:
+ cephThrowNotDir(env, "");
+ return;
default:
break;
}
diff --git a/src/java/test/com/ceph/fs/CephMountTest.java b/src/java/test/com/ceph/fs/CephMountTest.java
index 859ffa62f9b..026d2a9ed0d 100644
--- a/src/java/test/com/ceph/fs/CephMountTest.java
+++ b/src/java/test/com/ceph/fs/CephMountTest.java
@@ -485,6 +485,20 @@ public class CephMountTest {
assertTrue(orig_st.blocks == other_st.blocks);
}
+ @Test(expected=CephNotDirectoryException.class)
+ public void test_enotdir() throws Exception {
+ String path = makePath();
+ int fd = createFile(path, 1);
+ mount.close(fd);
+
+ try {
+ CephStat stat = new CephStat();
+ mount.lstat(path + "/blah", stat);
+ } finally {
+ mount.unlink(path);
+ }
+ }
+
/*
* setattr
*/