Merge pull request #432 from andrewgaul/create-bucket-location

Include location constraint when creating bucket
This commit is contained in:
Takeshi Nakatani 2016-06-26 09:39:47 +09:00 committed by GitHub
commit 49ffaa1d94

View File

@ -875,11 +875,32 @@ static int do_create_bucket(void)
{
S3FS_PRN_INFO2("/");
FILE* ptmpfp;
int tmpfd;
if(endpoint == "us-east-1"){
ptmpfp = NULL;
tmpfd = -1;
}else{
if(NULL == (ptmpfp = tmpfile()) ||
-1 == (tmpfd = fileno(ptmpfp)) ||
0 >= fprintf(ptmpfp, "<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n"
" <LocationConstraint>%s</LocationConstraint>\n"
"</CreateBucketConfiguration>", endpoint.c_str()) ||
0 != fflush(ptmpfp) ||
-1 == fseek(ptmpfp, 0L, SEEK_SET)){
S3FS_PRN_ERR("failed to create temporary file. err(%d)", errno);
if(ptmpfp){
fclose(ptmpfp);
}
return (0 == errno ? -EIO : -errno);
}
}
headers_t meta;
S3fsCurl s3fscurl(true);
long res = s3fscurl.PutRequest("/", meta, -1);
if(res < 0){ // fd=-1 means for creating zero byte object.
long res = s3fscurl.PutRequest("/", meta, tmpfd);
if(res < 0){
long responseCode = s3fscurl.GetLastResponseCode();
if((responseCode == 400 || responseCode == 403) && S3fsCurl::IsSignatureV4()){
S3FS_PRN_ERR("Could not connect, so retry to connect by signature version 2.");
@ -887,9 +908,12 @@ static int do_create_bucket(void)
// retry to check
s3fscurl.DestroyCurlHandle();
res = s3fscurl.PutRequest("/", meta, -1);
res = s3fscurl.PutRequest("/", meta, tmpfd);
}
}
if(ptmpfp != NULL){
fclose(ptmpfp);
}
return res;
}
@ -3366,7 +3390,11 @@ static void* s3fs_init(struct fuse_conn_info* conn)
}
if (create_bucket){
do_create_bucket();
int result = do_create_bucket();
if(result != 0){
s3fs_exit_fuseloop(result);
return NULL;
}
}
// Check Bucket