mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 09:18:55 +00:00
cleanup HTTP DELETE operations to use the same curl interface
git-svn-id: http://s3fs.googlecode.com/svn/trunk@381 df820570-a93a-0410-bd06-b72b767a4274
This commit is contained in:
parent
9fb05fba4f
commit
79ee801b94
46
src/curl.cpp
46
src/curl.cpp
@ -40,6 +40,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "curl.h"
|
#include "curl.h"
|
||||||
|
#include "string_util.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -48,6 +49,21 @@ std::map<CURL*, time_t> curl_times;
|
|||||||
std::map<CURL*, progress_t> curl_progress;
|
std::map<CURL*, progress_t> curl_progress;
|
||||||
std::string curl_ca_bundle;
|
std::string curl_ca_bundle;
|
||||||
|
|
||||||
|
class auto_curl_slist {
|
||||||
|
public:
|
||||||
|
auto_curl_slist() : slist(0) { }
|
||||||
|
~auto_curl_slist() { curl_slist_free_all(slist); }
|
||||||
|
|
||||||
|
struct curl_slist* get() const { return slist; }
|
||||||
|
|
||||||
|
void append(const string& s) {
|
||||||
|
slist = curl_slist_append(slist, s.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct curl_slist* slist;
|
||||||
|
};
|
||||||
|
|
||||||
CURL *create_curl_handle(void) {
|
CURL *create_curl_handle(void) {
|
||||||
time_t now;
|
time_t now;
|
||||||
CURL *curl_handle;
|
CURL *curl_handle;
|
||||||
@ -88,6 +104,36 @@ void destroy_curl_handle(CURL *curl_handle) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int curl_delete(const char *path) {
|
||||||
|
int result;
|
||||||
|
string date;
|
||||||
|
string url;
|
||||||
|
string my_url;
|
||||||
|
string resource;
|
||||||
|
auto_curl_slist headers;
|
||||||
|
CURL *curl = NULL;
|
||||||
|
|
||||||
|
resource = urlEncode(service_path + bucket + path);
|
||||||
|
url = host + resource;
|
||||||
|
date = get_date();
|
||||||
|
|
||||||
|
headers.append("Date: " + date);
|
||||||
|
headers.append("Content-Type: ");
|
||||||
|
if(public_bucket.substr(0,1) != "1")
|
||||||
|
headers.append("Authorization: AWS " + AWSAccessKeyId + ":" +
|
||||||
|
calc_signature("DELETE", "", date, headers.get(), resource));
|
||||||
|
|
||||||
|
my_url = prepare_url(url.c_str());
|
||||||
|
curl = create_curl_handle();
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str());
|
||||||
|
result = my_curl_easy_perform(curl);
|
||||||
|
destroy_curl_handle(curl);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return fuse return code
|
* @return fuse return code
|
||||||
*/
|
*/
|
||||||
|
@ -21,12 +21,18 @@ extern time_t readwrite_timeout;
|
|||||||
extern bool debug;
|
extern bool debug;
|
||||||
extern std::string program_name;
|
extern std::string program_name;
|
||||||
extern std::string ssl_verify_hostname;
|
extern std::string ssl_verify_hostname;
|
||||||
|
extern std::string AWSAccessKeyId;
|
||||||
extern std::string AWSSecretAccessKey;
|
extern std::string AWSSecretAccessKey;
|
||||||
|
extern std::string service_path;
|
||||||
|
extern std::string host;
|
||||||
|
extern std::string bucket;
|
||||||
|
extern std::string public_bucket;
|
||||||
|
|
||||||
static const EVP_MD* evp_md = EVP_sha1();
|
static const EVP_MD* evp_md = EVP_sha1();
|
||||||
|
|
||||||
CURL *create_curl_handle(void);
|
CURL *create_curl_handle(void);
|
||||||
void destroy_curl_handle(CURL *curl_handle);
|
void destroy_curl_handle(CURL *curl_handle);
|
||||||
|
int curl_delete(const char *path);
|
||||||
int my_curl_easy_perform(CURL* curl, BodyStruct* body = NULL, FILE* f = 0);
|
int my_curl_easy_perform(CURL* curl, BodyStruct* body = NULL, FILE* f = 0);
|
||||||
size_t WriteMemoryCallback(void *ptr, size_t blockSize, size_t numBlocks, void *data);
|
size_t WriteMemoryCallback(void *ptr, size_t blockSize, size_t numBlocks, void *data);
|
||||||
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp);
|
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp);
|
||||||
|
69
src/s3fs.cpp
69
src/s3fs.cpp
@ -1716,48 +1716,20 @@ static int s3fs_mkdir(const char *path, mode_t mode) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// aka rm
|
|
||||||
static int s3fs_unlink(const char *path) {
|
static int s3fs_unlink(const char *path) {
|
||||||
int result;
|
int result;
|
||||||
string date;
|
|
||||||
string url;
|
|
||||||
string my_url;
|
|
||||||
string resource;
|
|
||||||
char *s3_realpath;
|
char *s3_realpath;
|
||||||
auto_curl_slist headers;
|
|
||||||
CURL *curl = NULL;
|
|
||||||
|
|
||||||
if(foreground)
|
if(foreground)
|
||||||
cout << "unlink[path=" << path << "]" << endl;
|
printf("unlink[path=%s]\n", path);
|
||||||
|
|
||||||
s3_realpath = get_realpath(path);
|
s3_realpath = get_realpath(path);
|
||||||
resource = urlEncode(service_path + bucket + s3_realpath);
|
|
||||||
url = host + resource;
|
|
||||||
date = get_date();
|
|
||||||
|
|
||||||
headers.append("Date: " + date);
|
result = curl_delete(s3_realpath);
|
||||||
headers.append("Content-Type: ");
|
|
||||||
if(public_bucket.substr(0,1) != "1")
|
|
||||||
headers.append("Authorization: AWS " + AWSAccessKeyId + ":" +
|
|
||||||
calc_signature("DELETE", "", date, headers.get(), resource));
|
|
||||||
|
|
||||||
my_url = prepare_url(url.c_str());
|
|
||||||
curl = create_curl_handle();
|
|
||||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers.get());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, my_url.c_str());
|
|
||||||
|
|
||||||
result = my_curl_easy_perform(curl);
|
|
||||||
|
|
||||||
destroy_curl_handle(curl);
|
|
||||||
free(s3_realpath);
|
free(s3_realpath);
|
||||||
|
|
||||||
if(result != 0)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
delete_stat_cache_entry(path);
|
delete_stat_cache_entry(path);
|
||||||
|
|
||||||
return 0;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int directory_empty(const char *path) {
|
static int directory_empty(const char *path) {
|
||||||
@ -1823,57 +1795,24 @@ static int directory_empty(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int s3fs_rmdir(const char *path) {
|
static int s3fs_rmdir(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)
|
if(foreground)
|
||||||
printf("s3fs_rmdir [path=%s]\n", path);
|
printf("s3fs_rmdir [path=%s]\n", path);
|
||||||
|
|
||||||
s3_realpath = get_realpath(path);
|
s3_realpath = get_realpath(path);
|
||||||
body.text = (char *)malloc(1);
|
|
||||||
body.size = 0;
|
|
||||||
|
|
||||||
// directory must be empty
|
// directory must be empty
|
||||||
if(directory_empty(path) != 0)
|
if(directory_empty(path) != 0)
|
||||||
return -ENOTEMPTY;
|
return -ENOTEMPTY;
|
||||||
|
|
||||||
// delete the directory
|
result = curl_delete(s3_realpath);
|
||||||
string resource = urlEncode(service_path + bucket + s3_realpath);
|
|
||||||
string url = host + resource;
|
|
||||||
|
|
||||||
curl_handle = create_curl_handle();
|
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
|
|
||||||
|
|
||||||
auto_curl_slist headers;
|
|
||||||
string date = get_date();
|
|
||||||
headers.append("Date: " + date);
|
|
||||||
headers.append("Content-Type: ");
|
|
||||||
if (public_bucket.substr(0,1) != "1") {
|
|
||||||
headers.append("Authorization: AWS " + AWSAccessKeyId + ":" +
|
|
||||||
calc_signature("DELETE", "", date, headers.get(), resource));
|
|
||||||
}
|
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers.get());
|
|
||||||
|
|
||||||
string my_url = prepare_url(url.c_str());
|
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_URL, my_url.c_str());
|
|
||||||
|
|
||||||
result = my_curl_easy_perform(curl_handle);
|
|
||||||
|
|
||||||
// delete cache entry
|
|
||||||
delete_stat_cache_entry(path);
|
delete_stat_cache_entry(path);
|
||||||
|
|
||||||
if(body.text) free(body.text);
|
|
||||||
free(s3_realpath);
|
free(s3_realpath);
|
||||||
destroy_curl_handle(curl);
|
|
||||||
destroy_curl_handle(curl_handle);
|
|
||||||
|
|
||||||
if(result != 0)
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int s3fs_symlink(const char *from, const char *to) {
|
static int s3fs_symlink(const char *from, const char *to) {
|
||||||
|
@ -35,13 +35,13 @@ bool debug = 0;
|
|||||||
bool foreground = 0;
|
bool foreground = 0;
|
||||||
bool nomultipart = false;
|
bool nomultipart = false;
|
||||||
bool service_validated = false;
|
bool service_validated = false;
|
||||||
static std::string host = "http://s3.amazonaws.com";
|
std::string host = "http://s3.amazonaws.com";
|
||||||
static std::string service_path = "/";
|
std::string service_path = "/";
|
||||||
std::string bucket = "";
|
std::string bucket = "";
|
||||||
std::string mount_prefix = "";
|
std::string mount_prefix = "";
|
||||||
static std::string mountpoint;
|
static std::string mountpoint;
|
||||||
std::string program_name;
|
std::string program_name;
|
||||||
static std::string AWSAccessKeyId;
|
std::string AWSAccessKeyId;
|
||||||
std::string AWSSecretAccessKey;
|
std::string AWSSecretAccessKey;
|
||||||
static mode_t root_mode = 0;
|
static mode_t root_mode = 0;
|
||||||
static std::string passwd_file = "";
|
static std::string passwd_file = "";
|
||||||
@ -52,7 +52,7 @@ unsigned long max_stat_cache_size = 10000;
|
|||||||
static std::string use_cache;
|
static std::string use_cache;
|
||||||
static std::string use_rrs;
|
static std::string use_rrs;
|
||||||
std::string ssl_verify_hostname = "1";
|
std::string ssl_verify_hostname = "1";
|
||||||
static std::string public_bucket;
|
std::string public_bucket;
|
||||||
|
|
||||||
extern pthread_mutex_t stat_cache_lock;
|
extern pthread_mutex_t stat_cache_lock;
|
||||||
extern pthread_mutex_t curl_handles_lock;
|
extern pthread_mutex_t curl_handles_lock;
|
||||||
|
Loading…
Reference in New Issue
Block a user