-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfdfs.c
137 lines (115 loc) · 3.31 KB
/
fdfs.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright © 2014 newjueqi(http://www.newjueqi.com) All rights reserved.
// This file is part of go-client-for-fastdfs.
// go-client-for-fastdfs is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// go-client-for-fastdfs is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with go-client-for-fastdfs. If not, see <http://www.gnu.org/licenses/>.
#include "fdfs.h"
void usage(char *argv[])
{
printf("Usage: %s <config_file> <local_filename> " \
"[storage_ip:port] [store_path_index]\n", argv[0]);
}
responseData delete_file(char *conf_filename, char *file_name)
{
responseData res;
ConnectionInfo *pTrackerServer;
int result;
char file_id[200];
log_init();
g_log_context.log_level = LOG_ERR;
if ((result=fdfs_client_init(conf_filename)) != 0)
{
res.msg="fdfs_client_init failer";
res.result=0;
return res;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL)
{
fdfs_client_destroy();
res.msg="pTrackerServer connect failer";
res.result=0;
return res;
}
snprintf(file_id, sizeof(file_id), "%s", file_name);
if ((result=storage_delete_file1(pTrackerServer, NULL, file_id)) != 0)
{
printf("delete file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
res.msg="delete file fail";
res.result=0;
return res;
}
res.msg="delete file success";
res.result=1;
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return res;
}
responseData upload_file(char *conf_filename, char *local_filename)
{
responseData res;
char group_name[FDFS_GROUP_NAME_MAX_LEN + 1];
ConnectionInfo *pTrackerServer;
int result;
int store_path_index;
ConnectionInfo storageServer;
char file_id[200];
log_init();
g_log_context.log_level = LOG_ERR;
if ((result=fdfs_client_init(conf_filename)) != 0)
{
res.msg="fdfs_client_init failer";
res.result=0;
return res;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL)
{
fdfs_client_destroy();
res.msg="pTrackerServer connect failer";
res.result=0;
return res;
}
*group_name = '\0';
if ((result=tracker_query_storage_store(pTrackerServer, \
&storageServer, group_name, &store_path_index)) != 0)
{
fdfs_client_destroy();
fprintf(stderr, "tracker_query_storage fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
res.msg="tracker_query_storage fail";
res.result=0;
return res;
}
result = storage_upload_by_filename1(pTrackerServer, \
&storageServer, store_path_index, \
local_filename, NULL, \
NULL, 0, group_name, file_id);
if (result == 0)
{
printf("file path:%s\n", file_id);
res.msg=file_id;
res.result=1;
}
else
{
fprintf(stderr, "upload file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
res.msg="upload file fail";
res.result=0;
}
tracker_disconnect_server_ex(pTrackerServer, true);
fdfs_client_destroy();
return res;
}