mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-05 12:27:53 +00:00
cleaning up rmdir
git-svn-id: http://s3fs.googlecode.com/svn/trunk@372 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
parent
b481fa1d71
commit
ac54fad06e
54
src/s3fs.cpp
54
src/s3fs.cpp
@ -1898,29 +1898,22 @@ static int s3fs_unlink(const char *path) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s3fs_rmdir(const char *path) {
|
static int directory_empty(const char *path) {
|
||||||
CURL *curl = NULL;
|
|
||||||
CURL *curl_handle = NULL;
|
|
||||||
int result;
|
int result;
|
||||||
char *s3_realpath;
|
char *s3_realpath;
|
||||||
struct BodyStruct body;
|
|
||||||
|
|
||||||
if(foreground)
|
|
||||||
cout << "rmdir[path=" << path << "]" << endl;
|
|
||||||
|
|
||||||
s3_realpath = get_realpath(path);
|
|
||||||
body.text = (char *)malloc(1);
|
|
||||||
body.size = 0;
|
|
||||||
|
|
||||||
// need to check if the directory is empty
|
|
||||||
{
|
|
||||||
string url;
|
string url;
|
||||||
string my_url;
|
string my_url;
|
||||||
string date;
|
string date;
|
||||||
string resource = urlEncode(service_path + bucket);
|
string resource = urlEncode(service_path + bucket);
|
||||||
string query = "delimiter=/&prefix=";
|
string query = "delimiter=/&prefix=";
|
||||||
|
CURL *curl = NULL;
|
||||||
|
struct BodyStruct body;
|
||||||
auto_curl_slist headers;
|
auto_curl_slist headers;
|
||||||
|
|
||||||
|
s3_realpath = get_realpath(path);
|
||||||
|
body.text = (char *)malloc(1);
|
||||||
|
body.size = 0;
|
||||||
|
|
||||||
if(strcmp(path, "/") != 0)
|
if(strcmp(path, "/") != 0)
|
||||||
query += urlEncode(string(s3_realpath).substr(1) + "/");
|
query += urlEncode(string(s3_realpath).substr(1) + "/");
|
||||||
else
|
else
|
||||||
@ -1942,7 +1935,6 @@ static int s3fs_rmdir(const char *path) {
|
|||||||
headers.append("Authorization: AWS " + AWSAccessKeyId + ":" +
|
headers.append("Authorization: AWS " + AWSAccessKeyId + ":" +
|
||||||
calc_signature("GET", "", date, headers.get(), resource + "/"));
|
calc_signature("GET", "", date, headers.get(), resource + "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());
|
||||||
|
|
||||||
result = my_curl_easy_perform(curl, &body);
|
result = my_curl_easy_perform(curl, &body);
|
||||||
@ -1955,22 +1947,37 @@ static int s3fs_rmdir(const char *path) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is the directory empty?
|
||||||
if(strstr(body.text, "<CommonPrefixes>") != NULL ||
|
if(strstr(body.text, "<CommonPrefixes>") != NULL ||
|
||||||
strstr(body.text, "<ETag>") != NULL ) {
|
strstr(body.text, "<ETag>") != NULL ) {
|
||||||
// directory is not empty
|
if(body.text) free(body.text);
|
||||||
|
|
||||||
if(foreground)
|
|
||||||
cout << "[path=" << path << "] not empty" << endl;
|
|
||||||
|
|
||||||
if(body.text)
|
|
||||||
free(body.text);
|
|
||||||
free(s3_realpath);
|
free(s3_realpath);
|
||||||
destroy_curl_handle(curl);
|
destroy_curl_handle(curl);
|
||||||
|
|
||||||
return -ENOTEMPTY;
|
return -ENOTEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int s3fs_rmdir(const char *path) {
|
||||||
|
CURL *curl = NULL;
|
||||||
|
CURL *curl_handle = NULL;
|
||||||
|
int result;
|
||||||
|
char *s3_realpath;
|
||||||
|
struct BodyStruct body;
|
||||||
|
|
||||||
|
if(foreground)
|
||||||
|
printf("s3fs_rmdir [path=%s]\n", path);
|
||||||
|
|
||||||
|
s3_realpath = get_realpath(path);
|
||||||
|
body.text = (char *)malloc(1);
|
||||||
|
body.size = 0;
|
||||||
|
|
||||||
|
// directory must be empty
|
||||||
|
if(directory_empty(path) != 0)
|
||||||
|
return -ENOTEMPTY;
|
||||||
|
|
||||||
// delete the directory
|
// delete the directory
|
||||||
string resource = urlEncode(service_path + bucket + s3_realpath);
|
string resource = urlEncode(service_path + bucket + s3_realpath);
|
||||||
string url = host + resource;
|
string url = host + resource;
|
||||||
@ -1996,8 +2003,7 @@ static int s3fs_rmdir(const char *path) {
|
|||||||
// delete cache entry
|
// delete cache entry
|
||||||
delete_stat_cache_entry(path);
|
delete_stat_cache_entry(path);
|
||||||
|
|
||||||
if(body.text)
|
if(body.text) free(body.text);
|
||||||
free(body.text);
|
|
||||||
free(s3_realpath);
|
free(s3_realpath);
|
||||||
destroy_curl_handle(curl);
|
destroy_curl_handle(curl);
|
||||||
destroy_curl_handle(curl_handle);
|
destroy_curl_handle(curl_handle);
|
||||||
|
Loading…
Reference in New Issue
Block a user