-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathrs_batch_copy.c
79 lines (66 loc) · 2.26 KB
/
rs_batch_copy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Created by jemy on 07/08/2017.
//
#include "../qiniu/rs.h"
#include <stdlib.h>
#include "debug.h"
int main(int argc, char **argv) {
Qiniu_Global_Init(-1);
Qiniu_RS_BatchItemRet *itemRets;
Qiniu_Client client;
int i;
char *accessKey = getenv("QINIU_ACCESS_KEY");
char *secretKey = getenv("QINIU_SECRET_KEY");
char *bucket = getenv("QINIU_TEST_BUCKET");
char *key = "qiniu.png";
Qiniu_Mac mac;
mac.accessKey = accessKey;
mac.secretKey = secretKey;
Qiniu_ItemCount entryCount = 10;
Qiniu_RS_EntryPathPair *entryPairs = (Qiniu_RS_EntryPathPair *) malloc(sizeof(Qiniu_RS_EntryPathPair) * entryCount);
for (i = 0; i < entryCount; i++) {
//src
Qiniu_RS_EntryPath srcEntry;
srcEntry.bucket = bucket;
srcEntry.key = key;
//dest
Qiniu_RS_EntryPath destEntry;
destEntry.bucket = bucket;
size_t indexLen = snprintf(NULL, 0, "%d", i) + 1;
char *indexStr = (char *) calloc(sizeof(char), indexLen);
snprintf(indexStr, indexLen, "%d", i);
destEntry.key = Qiniu_String_Concat2(key, indexStr);
Qiniu_Free(indexStr);
//pack
Qiniu_RS_EntryPathPair entryPair;
entryPair.src = srcEntry;
entryPair.dest = destEntry;
entryPair.force = Qiniu_True;
entryPairs[i] = entryPair;
}
itemRets = (Qiniu_RS_BatchItemRet *) malloc(sizeof(Qiniu_RS_BatchItemRet) * entryCount);
//init
Qiniu_Client_InitMacAuth(&client, 1024, &mac);
Qiniu_Error error = Qiniu_RS_BatchCopy(&client, itemRets, entryPairs, entryCount);
if (error.code / 100 != 2) {
printf("batch copy file error.\n");
debug_log(&client, error);
} else {
printf("batch copy file success.\n\n");
for (i = 0; i < entryCount; i++) {
int code = itemRets[i].code;
if (code == 200) {
printf("success: %d\n", code);
} else {
printf("code: %d, error: %s\n", code, itemRets[i].error);
}
}
}
for (i = 0; i < entryCount; i++) {
Qiniu_RS_EntryPathPair entryPair = entryPairs[i];
Qiniu_Free((void *) entryPair.dest.key);
}
Qiniu_Free(entryPairs);
Qiniu_Free(itemRets);
Qiniu_Client_Cleanup(&client);
}