mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-02-08 21:48:26 +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;
|
||||
}
|
||||
|
||||
static int s3fs_rmdir(const char *path) {
|
||||
CURL *curl = NULL;
|
||||
CURL *curl_handle = NULL;
|
||||
static int directory_empty(const char *path) {
|
||||
int result;
|
||||
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 my_url;
|
||||
string date;
|
||||
string resource = urlEncode(service_path + bucket);
|
||||
string query = "delimiter=/&prefix=";
|
||||
CURL *curl = NULL;
|
||||
struct BodyStruct body;
|
||||
auto_curl_slist headers;
|
||||
|
||||
s3_realpath = get_realpath(path);
|
||||
body.text = (char *)malloc(1);
|
||||
body.size = 0;
|
||||
|
||||
if(strcmp(path, "/") != 0)
|
||||
query += urlEncode(string(s3_realpath).substr(1) + "/");
|
||||
else
|
||||
@ -1942,7 +1935,6 @@ static int s3fs_rmdir(const char *path) {
|
||||
headers.append("Authorization: AWS " + AWSAccessKeyId + ":" +
|
||||
calc_signature("GET", "", date, headers.get(), resource + "/"));
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());
|
||||
|
||||
result = my_curl_easy_perform(curl, &body);
|
||||
@ -1955,22 +1947,37 @@ static int s3fs_rmdir(const char *path) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// is the directory empty?
|
||||
if(strstr(body.text, "<CommonPrefixes>") != NULL ||
|
||||
strstr(body.text, "<ETag>") != NULL ) {
|
||||
// directory is not empty
|
||||
|
||||
if(foreground)
|
||||
cout << "[path=" << path << "] not empty" << endl;
|
||||
|
||||
if(body.text)
|
||||
free(body.text);
|
||||
if(body.text) free(body.text);
|
||||
free(s3_realpath);
|
||||
destroy_curl_handle(curl);
|
||||
|
||||
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
|
||||
string resource = urlEncode(service_path + bucket + s3_realpath);
|
||||
string url = host + resource;
|
||||
@ -1996,8 +2003,7 @@ static int s3fs_rmdir(const char *path) {
|
||||
// delete cache entry
|
||||
delete_stat_cache_entry(path);
|
||||
|
||||
if(body.text)
|
||||
free(body.text);
|
||||
if(body.text) free(body.text);
|
||||
free(s3_realpath);
|
||||
destroy_curl_handle(curl);
|
||||
destroy_curl_handle(curl_handle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user