Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int
- deltacloud_download_blob(struct deltacloud_api csp, char *bucket_id, char *blob_id, char *cache_path)
- {
- struct deltacloud_bucket bucket;
- if(deltacloud_get_bucket_by_id(&csp, bucket_id, &bucket)< 0)
- {
- fprintf(stderr, "DOWNLOAD: Failed to obtain bucket %s: %s.\n", bucket_id, deltacloud_get_last_error_string());
- return -1;
- }
- struct deltacloud_bucket_blob blob;
- if(deltacloud_bucket_get_blob_by_id(&csp, &bucket, blob_id, &blob)< 0)
- {
- fprintf(stderr, "DOWNLOAD: Failed to obtain file %s: %s.\n", blob_id, deltacloud_get_last_error_string());
- return -1;
- }
- FILE *fp;
- if((fp= fopen(cache_path, "w"))== NULL)
- {
- fprintf(stderr, "DOWNLOAD: Failed to create file %s.\n", cache_path);
- return -1;
- }
- u_int64_t blob_size= atoll(blob.content_length);
- char *buffer;
- fprintf(stderr, "DOWNLOAD: Getting a %d bytes-large file.\n", blob_size);
- if(deltacloud_bucket_blob_get_content(&csp, &blob, &buffer)< 0)
- {
- fprintf(stderr, "DOWNLOAD: Failed to obtain contents of blob %s: %s.\n", blob_id, deltacloud_get_last_error_string());
- return -1;
- }
- if((fwrite(buffer, sizeof(char), blob_size, fp))< blob_size)
- {
- fprintf(stderr, "DOWNLOAD: Failed to write contents of blob %s into the cache: %s.\n", blob_id, deltacloud_get_last_error_string());
- return -1;
- }
- fflush(fp);
- fclose(fp);
- free(buffer);
- deltacloud_free_bucket_blob(&blob);
- deltacloud_free_bucket(&bucket);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment