]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
java: add Java exception for ENOTDIR
authorNoah Watkins <noahwatkins@gmail.com>
Tue, 20 Nov 2012 21:44:47 +0000 (13:44 -0800)
committerNoah Watkins <noahwatkins@gmail.com>
Tue, 20 Nov 2012 21:55:32 +0000 (13:55 -0800)
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>
src/java/Makefile.am
src/java/java/com/ceph/fs/CephMount.java
src/java/java/com/ceph/fs/CephNotDirectoryException.java [new file with mode: 0644]
src/java/native/libcephfs_jni.cc
src/java/test/com/ceph/fs/CephMountTest.java

index f64129f1c3dccdaf106601a6c7dc6bae23e83366..55ff6c170df4448a00fa886e09bb1b019dcf2bf2 100644 (file)
@@ -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 \
index a30961f9245b4101911f1cdd04d8e9b57c09e466..d814804b92a9efddc4ead10729ee3e6602bb8537 100644 (file)
@@ -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 (file)
index 0000000..5181cb9
--- /dev/null
@@ -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);
+  }
+}
index b8fdd01e1cc6a2cc59c759827d755f27e23071f6..13132900d1619d28824af89b98e4586e441aa71a 100644 (file)
@@ -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;
   }
index 859ffa62f9b7fc257ab1ddef71666b2237f6c4c6..026d2a9ed0dbb495178d55132902a0732357fb63 100644 (file)
@@ -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
    */