Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/filesystems/curlftpfs/files/patch-ftpfs.c
16464 views
1
--- ftpfs.c.orig 2008-04-29 23:05:47 UTC
2
+++ ftpfs.c
3
@@ -257,6 +257,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_d
4
int err = 0;
5
CURLcode curl_res;
6
char* dir_path = get_fulldir_path(path);
7
+ char* dir_path_uri = path_to_uri(dir_path);
8
9
DEBUG(1, "ftpfs_getdir: %s\n", dir_path);
10
struct buffer buf;
11
@@ -264,7 +265,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_d
12
13
pthread_mutex_lock(&ftpfs.lock);
14
cancel_previous_multi();
15
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);
16
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);
17
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
18
curl_res = curl_easy_perform(ftpfs.connection);
19
pthread_mutex_unlock(&ftpfs.lock);
20
@@ -278,6 +279,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_d
21
NULL, NULL, NULL, 0, h, filler);
22
}
23
24
+ free_uri(dir_path_uri);
25
free(dir_path);
26
buf_free(&buf);
27
return op_return(err, "ftpfs_getdir");
28
@@ -287,6 +289,7 @@ static int ftpfs_getattr(const char* path, struct stat
29
int err;
30
CURLcode curl_res;
31
char* dir_path = get_dir_path(path);
32
+ char* dir_path_uri = path_to_uri(dir_path);
33
34
DEBUG(2, "ftpfs_getattr: %s dir_path=%s\n", path, dir_path);
35
struct buffer buf;
36
@@ -294,7 +297,7 @@ static int ftpfs_getattr(const char* path, struct stat
37
38
pthread_mutex_lock(&ftpfs.lock);
39
cancel_previous_multi();
40
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);
41
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);
42
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
43
curl_res = curl_easy_perform(ftpfs.connection);
44
pthread_mutex_unlock(&ftpfs.lock);
45
@@ -309,6 +312,7 @@ static int ftpfs_getattr(const char* path, struct stat
46
err = parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,
47
name, sbuf, NULL, 0, NULL, NULL);
48
49
+ free_uri(dir_path_uri);
50
free(dir_path);
51
buf_free(&buf);
52
if (err) return op_return(-ENOENT, "ftpfs_getattr");
53
@@ -329,6 +333,7 @@ static size_t ftpfs_read_chunk(const char* full_path,
54
int running_handles = 0;
55
int err = 0;
56
struct ftpfs_file* fh = get_ftpfs_file(fi);
57
+ char* full_path_uri = path_to_uri(full_path); /* TODO: optimize bu pushing up conversion to context */
58
59
DEBUG(2, "ftpfs_read_chunk: %s %p %zu %lld %p %p\n",
60
full_path, rbuf, size, offset, fi, fh);
61
@@ -355,7 +360,7 @@ static size_t ftpfs_read_chunk(const char* full_path,
62
63
cancel_previous_multi();
64
65
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
66
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
67
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &fh->buf);
68
if (offset) {
69
char range[15];
70
@@ -444,6 +449,7 @@ static size_t ftpfs_read_chunk(const char* full_path,
71
72
pthread_mutex_unlock(&ftpfs.lock);
73
74
+ free_uri(full_path_uri);
75
if (err) return CURLFTPFS_BAD_READ;
76
return size;
77
}
78
@@ -497,11 +503,12 @@ int write_thread_ctr = 0;
79
static void *ftpfs_write_thread(void *data) {
80
struct ftpfs_file *fh = data;
81
char range[15];
82
-
83
+ char* full_path_uri = path_to_uri(fh->full_path); /* TODO: optimize bu pushing up conversion to context */
84
+
85
DEBUG(2, "enter streaming write thread #%d path=%s pos=%lld\n", ++write_thread_ctr, fh->full_path, fh->pos);
86
87
88
- curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, fh->full_path);
89
+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, full_path_uri);
90
curl_easy_setopt_or_die(fh->write_conn, CURLOPT_UPLOAD, 1);
91
curl_easy_setopt_or_die(fh->write_conn, CURLOPT_INFILESIZE, -1);
92
curl_easy_setopt_or_die(fh->write_conn, CURLOPT_READFUNCTION, write_data_bg);
93
@@ -541,6 +548,8 @@ static void *ftpfs_write_thread(void *data) {
94
95
sem_post(&fh->data_written); /* ftpfs_write may return */
96
97
+ free_uri(full_path_uri);
98
+
99
return NULL;
100
}
101
102
@@ -619,16 +628,19 @@ static void free_ftpfs_file(struct ftpfs_file *fh) {
103
}
104
105
static int buffer_file(struct ftpfs_file *fh) {
106
+ char* full_path_uri = path_to_uri(fh->full_path); /* TODO: optimize bu pushing up conversion to context */
107
// If we want to write to the file, we have to load it all at once,
108
// modify it in memory and then upload it as a whole as most FTP servers
109
// don't support resume for uploads.
110
pthread_mutex_lock(&ftpfs.lock);
111
cancel_previous_multi();
112
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, fh->full_path);
113
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
114
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &fh->buf);
115
CURLcode curl_res = curl_easy_perform(ftpfs.connection);
116
pthread_mutex_unlock(&ftpfs.lock);
117
118
+ free_uri(full_path_uri);
119
+
120
if (curl_res != 0) {
121
return -EACCES;
122
}
123
@@ -641,10 +653,11 @@ static int create_empty_file(const char * path)
124
int err = 0;
125
126
char *full_path = get_full_path(path);
127
+ char* full_path_uri = path_to_uri(full_path);
128
129
pthread_mutex_lock(&ftpfs.lock);
130
cancel_previous_multi();
131
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
132
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
133
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_INFILESIZE, 0);
134
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_UPLOAD, 1);
135
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_READDATA, NULL);
136
@@ -654,7 +667,9 @@ static int create_empty_file(const char * path)
137
138
if (curl_res != 0) {
139
err = -EPERM;
140
- }
141
+ }
142
+
143
+ free_uri(full_path_uri);
144
free(full_path);
145
return err;
146
}
147
@@ -873,6 +888,7 @@ static int ftpfs_chmod(const char* path, mode_t mode)
148
149
struct curl_slist* header = NULL;
150
char* full_path = get_dir_path(path);
151
+ char* full_path_uri = path_to_uri(full_path);
152
char* filename = get_file_name(path);
153
char* cmd = g_strdup_printf("SITE CHMOD %.3o %s", mode_c, filename);
154
struct buffer buf;
155
@@ -883,7 +899,7 @@ static int ftpfs_chmod(const char* path, mode_t mode)
156
pthread_mutex_lock(&ftpfs.lock);
157
cancel_previous_multi();
158
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
159
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
160
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
161
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
162
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
163
CURLcode curl_res = curl_easy_perform(ftpfs.connection);
164
@@ -894,12 +910,13 @@ static int ftpfs_chmod(const char* path, mode_t mode)
165
if (curl_res != 0) {
166
err = -EPERM;
167
}
168
-
169
+
170
buf_free(&buf);
171
curl_slist_free_all(header);
172
+ free_uri(full_path_uri);
173
free(full_path);
174
free(filename);
175
- free(cmd);
176
+ free(cmd);
177
return op_return(err, "ftpfs_chmod");
178
}
179
180
@@ -910,6 +927,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gi
181
182
struct curl_slist* header = NULL;
183
char* full_path = get_dir_path(path);
184
+ char* full_path_uri = path_to_uri(full_path);
185
char* filename = get_file_name(path);
186
char* cmd = g_strdup_printf("SITE CHUID %i %s", uid, filename);
187
char* cmd2 = g_strdup_printf("SITE CHGID %i %s", gid, filename);
188
@@ -922,7 +940,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gi
189
pthread_mutex_lock(&ftpfs.lock);
190
cancel_previous_multi();
191
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
192
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
193
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
194
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
195
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
196
CURLcode curl_res = curl_easy_perform(ftpfs.connection);
197
@@ -936,6 +954,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gi
198
199
buf_free(&buf);
200
curl_slist_free_all(header);
201
+ free_uri(full_path_uri);
202
free(full_path);
203
free(filename);
204
free(cmd);
205
@@ -999,6 +1018,7 @@ static int ftpfs_rmdir(const char* path) {
206
int err = 0;
207
struct curl_slist* header = NULL;
208
char* full_path = get_dir_path(path);
209
+ char* full_path_uri = path_to_uri(full_path);
210
char* filename = get_file_name(path);
211
char* cmd = g_strdup_printf("RMD %s", filename);
212
struct buffer buf;
213
@@ -1012,7 +1032,7 @@ static int ftpfs_rmdir(const char* path) {
214
pthread_mutex_lock(&ftpfs.lock);
215
cancel_previous_multi();
216
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
217
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
218
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
219
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
220
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
221
CURLcode curl_res = curl_easy_perform(ftpfs.connection);
222
@@ -1026,6 +1046,7 @@ static int ftpfs_rmdir(const char* path) {
223
224
buf_free(&buf);
225
curl_slist_free_all(header);
226
+ free_uri(full_path_uri);
227
free(full_path);
228
free(filename);
229
free(cmd);
230
@@ -1036,6 +1057,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode)
231
int err = 0;
232
struct curl_slist* header = NULL;
233
char* full_path = get_dir_path(path);
234
+ char* full_path_uri = path_to_uri(full_path);
235
char* filename = get_file_name(path);
236
char* cmd = g_strdup_printf("MKD %s", filename);
237
struct buffer buf;
238
@@ -1046,7 +1068,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode)
239
pthread_mutex_lock(&ftpfs.lock);
240
cancel_previous_multi();
241
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
242
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
243
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
244
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
245
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
246
CURLcode curl_res = curl_easy_perform(ftpfs.connection);
247
@@ -1060,6 +1082,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode)
248
249
buf_free(&buf);
250
curl_slist_free_all(header);
251
+ free_uri(full_path_uri);
252
free(full_path);
253
free(filename);
254
free(cmd);
255
@@ -1074,6 +1097,7 @@ static int ftpfs_unlink(const char* path) {
256
int err = 0;
257
struct curl_slist* header = NULL;
258
char* full_path = get_dir_path(path);
259
+ char* full_path_uri = path_to_uri(full_path);
260
char* filename = get_file_name(path);
261
char* cmd = g_strdup_printf("DELE %s", filename);
262
struct buffer buf;
263
@@ -1084,7 +1108,7 @@ static int ftpfs_unlink(const char* path) {
264
pthread_mutex_lock(&ftpfs.lock);
265
cancel_previous_multi();
266
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);
267
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);
268
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);
269
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
270
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);
271
CURLcode curl_res = curl_easy_perform(ftpfs.connection);
272
@@ -1098,6 +1122,7 @@ static int ftpfs_unlink(const char* path) {
273
274
buf_free(&buf);
275
curl_slist_free_all(header);
276
+ free_uri(full_path_uri);
277
free(full_path);
278
free(filename);
279
free(cmd);
280
@@ -1299,6 +1324,7 @@ static int ftpfs_readlink(const char *path, char *link
281
int err;
282
CURLcode curl_res;
283
char* dir_path = get_dir_path(path);
284
+ char* dir_path_uri = path_to_uri(dir_path);
285
286
DEBUG(2, "dir_path: %s %s\n", path, dir_path);
287
struct buffer buf;
288
@@ -1306,7 +1332,7 @@ static int ftpfs_readlink(const char *path, char *link
289
290
pthread_mutex_lock(&ftpfs.lock);
291
cancel_previous_multi();
292
- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);
293
+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);
294
curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);
295
curl_res = curl_easy_perform(ftpfs.connection);
296
pthread_mutex_unlock(&ftpfs.lock);
297
@@ -1321,6 +1347,7 @@ static int ftpfs_readlink(const char *path, char *link
298
err = parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,
299
name, NULL, linkbuf, size, NULL, NULL);
300
301
+ free_uri(dir_path_uri);
302
free(dir_path);
303
buf_free(&buf);
304
if (err) return op_return(-ENOENT, "ftpfs_readlink");
305
306