Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cloudfiles mkdir()

  • Loading branch information...
commit 45b8e1674cbf3bb01c2fb2ec20c7c01942035b7f 1 parent 6417ce6
@benlemasurier authored
View
48 src/cloudfiles-curl.c
@@ -159,12 +159,8 @@ list_objects_url(const char *path)
char *url;
char *encoded_path = url_encode((char *) path);
- /*
- if(asprintf(&url, "%s/%s?format=json&delimiter=/&path=%s",
- cf_curl.storage_url, cf_curl.stormfs->bucket, encoded_path) == -1) {
- */
- if(asprintf(&url, "%s/%s?delimiter=/",
- cf_curl.storage_url, cf_curl.stormfs->bucket) == -1) {
+ if(asprintf(&url, "%s/%s?delimiter=/&path=%s",
+ cf_curl.storage_url, cf_curl.stormfs->bucket, (encoded_path + 1)) == -1) {
fprintf(stderr, "unable to allocate memory\n");
exit(EXIT_FAILURE);
}
@@ -546,3 +542,43 @@ cloudfiles_curl_put(const char *path, GList *headers)
return result;
}
+
+int
+cloudfiles_curl_upload(const char *path, GList *headers, int fd)
+{
+ int result;
+ FILE *f;
+ struct stat st;
+ HTTP_REQUEST *request;
+
+ if(fstat(fd, &st) != 0) {
+ perror("fstat");
+ return -errno;
+ }
+
+ /* TODO: multipart uploads */
+ if(st.st_size >= FIVE_GB)
+ return -EFBIG;
+
+ if(lseek(fd, 0, SEEK_SET) == -1) {
+ perror("lseek");
+ return -errno;
+ }
+
+ if((f = fdopen(fd, "rb")) == NULL) {
+ perror("fdopen");
+ return -errno;
+ }
+
+ headers = add_header(headers, auth_token_header(cf_curl.auth_token));
+ request = cloudfiles_request(path);
+ request->size = st.st_size;
+ request->headers = headers_to_curl_slist(headers);
+
+ curl_easy_setopt(request->c, CURLOPT_INFILE, f);
+
+ result = stormfs_curl_put(request);
+ free_request(request);
+
+ return result;
+}
View
1  src/cloudfiles-curl.h
@@ -24,5 +24,6 @@ int cloudfiles_curl_head(const char *path, GList **headers);
int cloudfiles_curl_head_multi(const char *path, GList *files);
int cloudfiles_curl_list_objects(const char *path, char **data);
int cloudfiles_curl_put(const char *path, GList *headers);
+int cloudfiles_curl_upload(const char *path, GList *headers, int fd);
#endif // cloudfiles_curl_H
View
22 src/cloudfiles.c
@@ -226,7 +226,27 @@ cloudfiles_init(struct stormfs *stormfs)
int
cloudfiles_mkdir(const char *path, struct stat *st)
{
- return -ENOTSUP;
+ int result, fd;
+ FILE *f;
+ GList *headers = NULL;
+
+ if((f = tmpfile()) == NULL)
+ return -errno;
+
+ if((fd = fileno(f)) == -1)
+ return -errno;
+
+ headers = stat_to_headers(headers, st);
+ headers = add_header(headers, content_header("application/x-directory"));
+ headers = optional_headers(headers);
+
+ result = cloudfiles_curl_upload(path, headers, fd);
+ free_headers(headers);
+
+ if(close(fd) != 0)
+ return -errno;
+
+ return result;
}
int
View
3  src/proxy.c
@@ -161,6 +161,9 @@ proxy_mkdir(const char *path, struct stat *st)
case S3:
result = s3_mkdir(path, st);
break;
+ case CLOUDFILES:
+ result = cloudfiles_mkdir(path, st);
+ break;
default:
result = -ENOTSUP;
}
Please sign in to comment.
Something went wrong with that request. Please try again.