diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 2851086..b64716c 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -114,6 +114,7 @@ static bool is_s3fs_uid = false;// default does not set. static bool is_s3fs_gid = false;// default does not set. static bool is_s3fs_umask = false;// default does not set. static bool is_remove_cache = false; +static bool create_bucket = false; //------------------------------------------------------------------- // Static functions : prototype @@ -782,6 +783,16 @@ static int s3fs_readlink(const char* path, char* buf, size_t size) return 0; } +static int do_create_bucket(void) +{ + FPRNNN("/"); + + headers_t meta; + + S3fsCurl s3fscurl(true); + return s3fscurl.PutRequest("/", meta, -1); // fd=-1 means for creating zero byte object. +} + // common function for creation of a plain object static int create_file_object(const char* path, mode_t mode, uid_t uid, gid_t gid) { @@ -2682,6 +2693,10 @@ static void* s3fs_init(struct fuse_conn_info* conn) exit(EXIT_FAILURE); } + if (create_bucket){ + do_create_bucket(); + } + // Check Bucket // If the network is up, check for valid credentials and if the bucket // exists. skip check if mounting a public bucket @@ -3862,6 +3877,10 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar S3fsCurl::SetSignatureV4(false); return 0; } + if(0 == strcmp(arg, "createbucket")){ + create_bucket = true; + return 0; + } if(0 == STR2NCMP(arg, "endpoint=")){ endpoint = strchr(arg, '=') + sizeof(char); is_specified_endpoint = true; diff --git a/test/integration-test-common.sh b/test/integration-test-common.sh index 96a09a9..c856250 100644 --- a/test/integration-test-common.sh +++ b/test/integration-test-common.sh @@ -2,9 +2,9 @@ S3FS=../src/s3fs -S3FS_CREDENTIALS_FILE=$(eval echo ~${SUDO_USER}/.passwd-s3fs) +S3FS_CREDENTIALS_FILE="passwd-s3fs" -TEST_BUCKET_1=${SUDO_USER}-s3fs-integration-test +TEST_BUCKET_1="s3fs-integration-test" TEST_BUCKET_MOUNT_POINT_1=${TEST_BUCKET_1} if [ ! -f "$S3FS_CREDENTIALS_FILE" ] @@ -12,3 +12,9 @@ then echo "Missing credentials file: $S3FS_CREDENTIALS_FILE" exit 1 fi + +S3PROXY_VERSION="1.3.0" +S3PROXY_BINARY="s3proxy-${S3PROXY_VERSION}-jar-with-dependencies.jar" +if [ ! -e "${S3PROXY_BINARY}" ]; then + wget "http://repo1.maven.org/maven2/org/gaul/s3proxy/${S3PROXY_VERSION}/${S3PROXY_BINARY}" +fi diff --git a/test/passwd-s3fs b/test/passwd-s3fs new file mode 100644 index 0000000..1f90d9c --- /dev/null +++ b/test/passwd-s3fs @@ -0,0 +1 @@ +local-identity:local-credential diff --git a/test/s3proxy.conf b/test/s3proxy.conf new file mode 100644 index 0000000..27f9bc4 --- /dev/null +++ b/test/s3proxy.conf @@ -0,0 +1,8 @@ +s3proxy.endpoint=http://127.0.0.1:8080 +s3proxy.authorization=aws-v2 +s3proxy.identity=local-identity +s3proxy.credential=local-credential + +jclouds.provider=transient +jclouds.identity=remote-identity +jclouds.credential=remote-credential diff --git a/test/small-integration-test.sh b/test/small-integration-test.sh index ef1da1e..75e8484 100755 --- a/test/small-integration-test.sh +++ b/test/small-integration-test.sh @@ -3,16 +3,39 @@ # Require root REQUIRE_ROOT=require-root.sh #source $REQUIRE_ROOT +source integration-test-common.sh + +java -jar "$S3PROXY_BINARY" --properties s3proxy.conf & +S3PROXY_PID="$?" + +# wait for S3Proxy to start +for i in $(seq 30); +do + if exec 3<>"/dev/tcp/localhost/8080"; + then + exec 3<&- # Close for read + exec 3>&- # Close for write + break + fi + sleep 1 +done # Mount the bucket if [ ! -d $TEST_BUCKET_MOUNT_POINT_1 ] then mkdir -p $TEST_BUCKET_MOUNT_POINT_1 fi -$S3FS $TEST_BUCKET_1 $TEST_BUCKET_MOUNT_POINT_1 -o passwd_file=$S3FS_CREDENTIALS_FILE +$S3FS $TEST_BUCKET_1 $TEST_BUCKET_MOUNT_POINT_1 \ + -o createbucket \ + -o passwd_file=$S3FS_CREDENTIALS_FILE \ + -o sigv2 \ + -o url=http://127.0.0.1:8080 \ + -o use_path_request_style ./integration-test-main.sh $TEST_BUCKET_MOUNT_POINT_1 umount $TEST_BUCKET_MOUNT_POINT_1 +kill $S3PROXY_PID + echo "All tests complete."