From 712bfa59b9d240586f5a9638f6c03313463b54b7 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Fri, 19 Oct 2012 12:10:25 -0700 Subject: [PATCH] java: add FileAlreadyExists exception Signed-off-by: Noah Watkins --- src/java/Makefile.am | 3 +- .../fs/CephFileAlreadyExistsException.java | 42 +++++++++++++++++++ src/java/native/libcephfs_jni.cc | 9 ++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/java/java/com/ceph/fs/CephFileAlreadyExistsException.java diff --git a/src/java/Makefile.am b/src/java/Makefile.am index c712cf78cba7f..48266653b0afa 100644 --- a/src/java/Makefile.am +++ b/src/java/Makefile.am @@ -5,7 +5,8 @@ JAVA_SRC = \ java/com/ceph/fs/CephStat.java \ java/com/ceph/fs/CephStatVFS.java \ java/com/ceph/fs/CephNativeLoader.java \ - java/com/ceph/fs/CephNotMountedException.java + java/com/ceph/fs/CephNotMountedException.java \ + java/com/ceph/fs/CephFileAlreadyExistsException.java EXTRA_DIST = $(JAVA_SRC) test diff --git a/src/java/java/com/ceph/fs/CephFileAlreadyExistsException.java b/src/java/java/com/ceph/fs/CephFileAlreadyExistsException.java new file mode 100644 index 0000000000000..f750a6ef7f5a3 --- /dev/null +++ b/src/java/java/com/ceph/fs/CephFileAlreadyExistsException.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; + +/** + * Ceph file/directory already exists. + */ +public class CephFileAlreadyExistsException extends IOException { + + /** + * Construct CephFileAlreadyExistsException. + */ + public CephFileAlreadyExistsException() { + super(); + } + + /** + * Construct CephFileAlreadyExistsException with message. + */ + public CephFileAlreadyExistsException(String s) { + super(s); + } +} diff --git a/src/java/native/libcephfs_jni.cc b/src/java/native/libcephfs_jni.cc index fe5ce754f321e..dd23c36d6e180 100644 --- a/src/java/native/libcephfs_jni.cc +++ b/src/java/native/libcephfs_jni.cc @@ -36,6 +36,7 @@ #define CEPH_STAT_VFS_CP "com/ceph/fs/CephStatVFS" #define CEPH_MOUNT_CP "com/ceph/fs/CephMount" #define CEPH_NOTMOUNTED_CP "com/ceph/fs/CephNotMountedException" +#define CEPH_FILEEXISTS_CP "com/ceph/fs/CephFileAlreadyExistsException" /* * Flags to open(). must be synchronized with CephMount.java @@ -191,12 +192,20 @@ static void cephThrowFNF(JNIEnv *env, const char *msg) THROW(env, "java/io/FileNotFoundException", msg); } +static void cephThrowFileExists(JNIEnv *env, const char *msg) +{ + THROW(env, CEPH_FILEEXISTS_CP, msg); +} + static void handle_error(JNIEnv *env, int rc) { switch (rc) { case -ENOENT: cephThrowFNF(env, ""); return; + case -EEXIST: + cephThrowFileExists(env, ""); + return; default: break; } -- 2.39.5