diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/fs/fs_dirmetascan.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/fs/fs_dirmetascan.c')
-rw-r--r-- | src/fs/fs_dirmetascan.c | 453 |
1 files changed, 228 insertions, 225 deletions
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index 9202de5ab..11efa053b 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -35,7 +35,8 @@ | |||
35 | * An opaque structure a pointer to which is returned to the | 35 | * An opaque structure a pointer to which is returned to the |
36 | * caller to be used to control the scanner. | 36 | * caller to be used to control the scanner. |
37 | */ | 37 | */ |
38 | struct GNUNET_FS_DirScanner { | 38 | struct GNUNET_FS_DirScanner |
39 | { | ||
39 | /** | 40 | /** |
40 | * Helper process. | 41 | * Helper process. |
41 | */ | 42 | */ |
@@ -94,20 +95,20 @@ struct GNUNET_FS_DirScanner { | |||
94 | * @param ds directory scanner structure | 95 | * @param ds directory scanner structure |
95 | */ | 96 | */ |
96 | void | 97 | void |
97 | GNUNET_FS_directory_scan_abort(struct GNUNET_FS_DirScanner *ds) | 98 | GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds) |
98 | { | 99 | { |
99 | /* terminate helper */ | 100 | /* terminate helper */ |
100 | if (NULL != ds->helper) | 101 | if (NULL != ds->helper) |
101 | GNUNET_HELPER_stop(ds->helper, GNUNET_NO); | 102 | GNUNET_HELPER_stop (ds->helper, GNUNET_NO); |
102 | 103 | ||
103 | /* free resources */ | 104 | /* free resources */ |
104 | if (NULL != ds->toplevel) | 105 | if (NULL != ds->toplevel) |
105 | GNUNET_FS_share_tree_free(ds->toplevel); | 106 | GNUNET_FS_share_tree_free (ds->toplevel); |
106 | if (NULL != ds->stop_task) | 107 | if (NULL != ds->stop_task) |
107 | GNUNET_SCHEDULER_cancel(ds->stop_task); | 108 | GNUNET_SCHEDULER_cancel (ds->stop_task); |
108 | GNUNET_free_non_null(ds->ex_arg); | 109 | GNUNET_free_non_null (ds->ex_arg); |
109 | GNUNET_free(ds->filename_expanded); | 110 | GNUNET_free (ds->filename_expanded); |
110 | GNUNET_free(ds); | 111 | GNUNET_free (ds); |
111 | } | 112 | } |
112 | 113 | ||
113 | 114 | ||
@@ -120,16 +121,16 @@ GNUNET_FS_directory_scan_abort(struct GNUNET_FS_DirScanner *ds) | |||
120 | * @return the results of the scan (a directory tree) | 121 | * @return the results of the scan (a directory tree) |
121 | */ | 122 | */ |
122 | struct GNUNET_FS_ShareTreeItem * | 123 | struct GNUNET_FS_ShareTreeItem * |
123 | GNUNET_FS_directory_scan_get_result(struct GNUNET_FS_DirScanner *ds) | 124 | GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds) |
124 | { | 125 | { |
125 | struct GNUNET_FS_ShareTreeItem *result; | 126 | struct GNUNET_FS_ShareTreeItem *result; |
126 | 127 | ||
127 | /* check that we're actually done */ | 128 | /* check that we're actually done */ |
128 | GNUNET_assert(NULL == ds->helper); | 129 | GNUNET_assert (NULL == ds->helper); |
129 | /* preserve result */ | 130 | /* preserve result */ |
130 | result = ds->toplevel; | 131 | result = ds->toplevel; |
131 | ds->toplevel = NULL; | 132 | ds->toplevel = NULL; |
132 | GNUNET_FS_directory_scan_abort(ds); | 133 | GNUNET_FS_directory_scan_abort (ds); |
133 | return result; | 134 | return result; |
134 | } | 135 | } |
135 | 136 | ||
@@ -142,35 +143,35 @@ GNUNET_FS_directory_scan_get_result(struct GNUNET_FS_DirScanner *ds) | |||
142 | * @return next file, NULL for none | 143 | * @return next file, NULL for none |
143 | */ | 144 | */ |
144 | static struct GNUNET_FS_ShareTreeItem * | 145 | static struct GNUNET_FS_ShareTreeItem * |
145 | advance(struct GNUNET_FS_ShareTreeItem *pos) | 146 | advance (struct GNUNET_FS_ShareTreeItem *pos) |
146 | { | 147 | { |
147 | int moved; | 148 | int moved; |
148 | 149 | ||
149 | GNUNET_assert(NULL != pos); | 150 | GNUNET_assert (NULL != pos); |
150 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ | 151 | moved = 0; /* must not terminate, even on file, otherwise "normal" */ |
151 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) | 152 | while ((pos->is_directory == GNUNET_YES) || (0 == moved)) |
153 | { | ||
154 | if ((moved != -1) && (NULL != pos->children_head)) | ||
152 | { | 155 | { |
153 | if ((moved != -1) && (NULL != pos->children_head)) | 156 | pos = pos->children_head; |
154 | { | 157 | moved = 1; /* can terminate if file */ |
155 | pos = pos->children_head; | 158 | continue; |
156 | moved = 1; /* can terminate if file */ | 159 | } |
157 | continue; | 160 | if (NULL != pos->next) |
158 | } | 161 | { |
159 | if (NULL != pos->next) | 162 | pos = pos->next; |
160 | { | 163 | moved = 1; /* can terminate if file */ |
161 | pos = pos->next; | 164 | continue; |
162 | moved = 1; /* can terminate if file */ | 165 | } |
163 | continue; | 166 | if (NULL != pos->parent) |
164 | } | 167 | { |
165 | if (NULL != pos->parent) | 168 | pos = pos->parent; |
166 | { | 169 | moved = -1; /* force move to 'next' or 'parent' */ |
167 | pos = pos->parent; | 170 | continue; |
168 | moved = -1; /* force move to 'next' or 'parent' */ | ||
169 | continue; | ||
170 | } | ||
171 | /* no more options, end of traversal */ | ||
172 | return NULL; | ||
173 | } | 171 | } |
172 | /* no more options, end of traversal */ | ||
173 | return NULL; | ||
174 | } | ||
174 | return pos; | 175 | return pos; |
175 | } | 176 | } |
176 | 177 | ||
@@ -184,30 +185,30 @@ advance(struct GNUNET_FS_ShareTreeItem *pos) | |||
184 | * @return new entry that was just created | 185 | * @return new entry that was just created |
185 | */ | 186 | */ |
186 | static struct GNUNET_FS_ShareTreeItem * | 187 | static struct GNUNET_FS_ShareTreeItem * |
187 | expand_tree(struct GNUNET_FS_ShareTreeItem *parent, | 188 | expand_tree (struct GNUNET_FS_ShareTreeItem *parent, |
188 | const char *filename, | 189 | const char *filename, |
189 | int is_directory) | 190 | int is_directory) |
190 | { | 191 | { |
191 | struct GNUNET_FS_ShareTreeItem *chld; | 192 | struct GNUNET_FS_ShareTreeItem *chld; |
192 | size_t slen; | 193 | size_t slen; |
193 | 194 | ||
194 | chld = GNUNET_new(struct GNUNET_FS_ShareTreeItem); | 195 | chld = GNUNET_new (struct GNUNET_FS_ShareTreeItem); |
195 | chld->parent = parent; | 196 | chld->parent = parent; |
196 | chld->filename = GNUNET_strdup(filename); | 197 | chld->filename = GNUNET_strdup (filename); |
197 | GNUNET_asprintf(&chld->short_filename, | 198 | GNUNET_asprintf (&chld->short_filename, |
198 | "%s%s", | 199 | "%s%s", |
199 | GNUNET_STRINGS_get_short_name(filename), | 200 | GNUNET_STRINGS_get_short_name (filename), |
200 | is_directory == GNUNET_YES ? "/" : ""); | 201 | is_directory == GNUNET_YES ? "/" : ""); |
201 | /* make sure we do not end with '//' */ | 202 | /* make sure we do not end with '//' */ |
202 | slen = strlen(chld->short_filename); | 203 | slen = strlen (chld->short_filename); |
203 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && | 204 | if ((slen >= 2) && (chld->short_filename[slen - 1] == '/') && |
204 | (chld->short_filename[slen - 2] == '/')) | 205 | (chld->short_filename[slen - 2] == '/')) |
205 | chld->short_filename[slen - 1] = '\0'; | 206 | chld->short_filename[slen - 1] = '\0'; |
206 | chld->is_directory = is_directory; | 207 | chld->is_directory = is_directory; |
207 | if (NULL != parent) | 208 | if (NULL != parent) |
208 | GNUNET_CONTAINER_DLL_insert(parent->children_head, | 209 | GNUNET_CONTAINER_DLL_insert (parent->children_head, |
209 | parent->children_tail, | 210 | parent->children_tail, |
210 | chld); | 211 | chld); |
211 | return chld; | 212 | return chld; |
212 | } | 213 | } |
213 | 214 | ||
@@ -218,20 +219,20 @@ expand_tree(struct GNUNET_FS_ShareTreeItem *parent, | |||
218 | * @param cls the 'struct GNUNET_FS_DirScanner' | 219 | * @param cls the 'struct GNUNET_FS_DirScanner' |
219 | */ | 220 | */ |
220 | static void | 221 | static void |
221 | finish_scan(void *cls) | 222 | finish_scan (void *cls) |
222 | { | 223 | { |
223 | struct GNUNET_FS_DirScanner *ds = cls; | 224 | struct GNUNET_FS_DirScanner *ds = cls; |
224 | 225 | ||
225 | ds->stop_task = NULL; | 226 | ds->stop_task = NULL; |
226 | if (NULL != ds->helper) | 227 | if (NULL != ds->helper) |
227 | { | 228 | { |
228 | GNUNET_HELPER_stop(ds->helper, GNUNET_NO); | 229 | GNUNET_HELPER_stop (ds->helper, GNUNET_NO); |
229 | ds->helper = NULL; | 230 | ds->helper = NULL; |
230 | } | 231 | } |
231 | ds->progress_callback(ds->progress_callback_cls, | 232 | ds->progress_callback (ds->progress_callback_cls, |
232 | NULL, | 233 | NULL, |
233 | GNUNET_SYSERR, | 234 | GNUNET_SYSERR, |
234 | GNUNET_FS_DIRSCANNER_FINISHED); | 235 | GNUNET_FS_DIRSCANNER_FINISHED); |
235 | } | 236 | } |
236 | 237 | ||
237 | 238 | ||
@@ -246,175 +247,177 @@ finish_scan(void *cls) | |||
246 | * #GNUNET_SYSERR to stop further processing with error | 247 | * #GNUNET_SYSERR to stop further processing with error |
247 | */ | 248 | */ |
248 | static int | 249 | static int |
249 | process_helper_msgs(void *cls, const struct GNUNET_MessageHeader *msg) | 250 | process_helper_msgs (void *cls, const struct GNUNET_MessageHeader *msg) |
250 | { | 251 | { |
251 | struct GNUNET_FS_DirScanner *ds = cls; | 252 | struct GNUNET_FS_DirScanner *ds = cls; |
252 | const char *filename; | 253 | const char *filename; |
253 | size_t left; | 254 | size_t left; |
254 | 255 | ||
255 | #if 0 | 256 | #if 0 |
256 | fprintf(stderr, | 257 | fprintf (stderr, |
257 | "DMS parses %u-byte message of type %u\n", | 258 | "DMS parses %u-byte message of type %u\n", |
258 | (unsigned int)ntohs(msg->size), | 259 | (unsigned int) ntohs (msg->size), |
259 | (unsigned int)ntohs(msg->type)); | 260 | (unsigned int) ntohs (msg->type)); |
260 | #endif | 261 | #endif |
261 | left = ntohs(msg->size) - sizeof(struct GNUNET_MessageHeader); | 262 | left = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader); |
262 | filename = (const char *)&msg[1]; | 263 | filename = (const char *) &msg[1]; |
263 | switch (ntohs(msg->type)) | 264 | switch (ntohs (msg->type)) |
265 | { | ||
266 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: | ||
267 | if (filename[left - 1] != '\0') | ||
264 | { | 268 | { |
265 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE: | 269 | GNUNET_break (0); |
266 | if (filename[left - 1] != '\0') | ||
267 | { | ||
268 | GNUNET_break(0); | ||
269 | break; | ||
270 | } | ||
271 | ds->progress_callback(ds->progress_callback_cls, | ||
272 | filename, | ||
273 | GNUNET_NO, | ||
274 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
275 | if (NULL == ds->toplevel) | ||
276 | { | ||
277 | ds->toplevel = expand_tree(ds->pos, filename, GNUNET_NO); | ||
278 | } | ||
279 | else | ||
280 | { | ||
281 | GNUNET_assert(NULL != ds->pos); | ||
282 | (void)expand_tree(ds->pos, filename, GNUNET_NO); | ||
283 | } | ||
284 | return GNUNET_OK; | ||
285 | |||
286 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: | ||
287 | if (filename[left - 1] != '\0') | ||
288 | { | ||
289 | GNUNET_break(0); | ||
290 | break; | ||
291 | } | ||
292 | if (0 == strcmp("..", filename)) | ||
293 | { | ||
294 | if (NULL == ds->pos) | ||
295 | { | ||
296 | GNUNET_break(0); | ||
297 | break; | ||
298 | } | ||
299 | ds->pos = ds->pos->parent; | ||
300 | return GNUNET_OK; | ||
301 | } | ||
302 | ds->progress_callback(ds->progress_callback_cls, | ||
303 | filename, | ||
304 | GNUNET_YES, | ||
305 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
306 | ds->pos = expand_tree(ds->pos, filename, GNUNET_YES); | ||
307 | if (NULL == ds->toplevel) | ||
308 | ds->toplevel = ds->pos; | ||
309 | return GNUNET_OK; | ||
310 | |||
311 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: | ||
312 | break; | 270 | break; |
271 | } | ||
272 | ds->progress_callback (ds->progress_callback_cls, | ||
273 | filename, | ||
274 | GNUNET_NO, | ||
275 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
276 | if (NULL == ds->toplevel) | ||
277 | { | ||
278 | ds->toplevel = expand_tree (ds->pos, filename, GNUNET_NO); | ||
279 | } | ||
280 | else | ||
281 | { | ||
282 | GNUNET_assert (NULL != ds->pos); | ||
283 | (void) expand_tree (ds->pos, filename, GNUNET_NO); | ||
284 | } | ||
285 | return GNUNET_OK; | ||
313 | 286 | ||
314 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: | 287 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY: |
315 | if ('\0' != filename[left - 1]) | 288 | if (filename[left - 1] != '\0') |
316 | break; | 289 | { |
317 | ds->progress_callback(ds->progress_callback_cls, | 290 | GNUNET_break (0); |
318 | filename, | 291 | break; |
319 | GNUNET_SYSERR, | 292 | } |
320 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | 293 | if (0 == strcmp ("..", filename)) |
321 | return GNUNET_OK; | 294 | { |
322 | 295 | if (NULL == ds->pos) | |
323 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: | 296 | { |
324 | if (0 != left) | 297 | GNUNET_break (0); |
325 | { | ||
326 | GNUNET_break(0); | ||
327 | break; | ||
328 | } | ||
329 | if (NULL == ds->toplevel) | ||
330 | break; | 298 | break; |
331 | ds->progress_callback(ds->progress_callback_cls, | 299 | } |
332 | NULL, | 300 | ds->pos = ds->pos->parent; |
333 | GNUNET_SYSERR, | ||
334 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | ||
335 | ds->pos = ds->toplevel; | ||
336 | if (GNUNET_YES == ds->pos->is_directory) | ||
337 | ds->pos = advance(ds->pos); | ||
338 | return GNUNET_OK; | 301 | return GNUNET_OK; |
339 | 302 | } | |
340 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { | 303 | ds->progress_callback (ds->progress_callback_cls, |
304 | filename, | ||
305 | GNUNET_YES, | ||
306 | GNUNET_FS_DIRSCANNER_FILE_START); | ||
307 | ds->pos = expand_tree (ds->pos, filename, GNUNET_YES); | ||
308 | if (NULL == ds->toplevel) | ||
309 | ds->toplevel = ds->pos; | ||
310 | return GNUNET_OK; | ||
311 | |||
312 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR: | ||
313 | break; | ||
314 | |||
315 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE: | ||
316 | if ('\0' != filename[left - 1]) | ||
317 | break; | ||
318 | ds->progress_callback (ds->progress_callback_cls, | ||
319 | filename, | ||
320 | GNUNET_SYSERR, | ||
321 | GNUNET_FS_DIRSCANNER_FILE_IGNORED); | ||
322 | return GNUNET_OK; | ||
323 | |||
324 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE: | ||
325 | if (0 != left) | ||
326 | { | ||
327 | GNUNET_break (0); | ||
328 | break; | ||
329 | } | ||
330 | if (NULL == ds->toplevel) | ||
331 | break; | ||
332 | ds->progress_callback (ds->progress_callback_cls, | ||
333 | NULL, | ||
334 | GNUNET_SYSERR, | ||
335 | GNUNET_FS_DIRSCANNER_ALL_COUNTED); | ||
336 | ds->pos = ds->toplevel; | ||
337 | if (GNUNET_YES == ds->pos->is_directory) | ||
338 | ds->pos = advance (ds->pos); | ||
339 | return GNUNET_OK; | ||
340 | |||
341 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA: { | ||
341 | size_t nlen; | 342 | size_t nlen; |
342 | const char *end; | 343 | const char *end; |
343 | 344 | ||
344 | if (NULL == ds->pos) | 345 | if (NULL == ds->pos) |
345 | { | 346 | { |
346 | GNUNET_break(0); | 347 | GNUNET_break (0); |
347 | break; | 348 | break; |
348 | } | 349 | } |
349 | end = memchr(filename, 0, left); | 350 | end = memchr (filename, 0, left); |
350 | if (NULL == end) | 351 | if (NULL == end) |
351 | { | 352 | { |
352 | GNUNET_break(0); | 353 | GNUNET_break (0); |
353 | break; | 354 | break; |
354 | } | 355 | } |
355 | end++; | 356 | end++; |
356 | nlen = end - filename; | 357 | nlen = end - filename; |
357 | left -= nlen; | 358 | left -= nlen; |
358 | if (0 != strcmp(filename, ds->pos->filename)) | 359 | if (0 != strcmp (filename, ds->pos->filename)) |
359 | { | 360 | { |
360 | GNUNET_break(0); | 361 | GNUNET_break (0); |
361 | break; | 362 | break; |
362 | } | 363 | } |
363 | ds->progress_callback(ds->progress_callback_cls, | 364 | ds->progress_callback (ds->progress_callback_cls, |
364 | filename, | 365 | filename, |
365 | GNUNET_YES, | 366 | GNUNET_YES, |
366 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); | 367 | GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED); |
367 | if (0 < left) | 368 | if (0 < left) |
369 | { | ||
370 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize (end, left); | ||
371 | if (NULL == ds->pos->meta) | ||
368 | { | 372 | { |
369 | ds->pos->meta = GNUNET_CONTAINER_meta_data_deserialize(end, left); | 373 | GNUNET_break (0); |
370 | if (NULL == ds->pos->meta) | ||
371 | { | ||
372 | GNUNET_break(0); | ||
373 | break; | ||
374 | } | ||
375 | /* having full filenames is too dangerous; always make sure we clean them up */ | ||
376 | GNUNET_CONTAINER_meta_data_delete(ds->pos->meta, | ||
377 | EXTRACTOR_METATYPE_FILENAME, | ||
378 | NULL, | ||
379 | 0); | ||
380 | /* instead, put in our 'safer' original filename */ | ||
381 | GNUNET_CONTAINER_meta_data_insert(ds->pos->meta, | ||
382 | "<libgnunetfs>", | ||
383 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
384 | EXTRACTOR_METAFORMAT_UTF8, | ||
385 | "text/plain", | ||
386 | ds->pos->short_filename, | ||
387 | strlen(ds->pos->short_filename) + 1); | ||
388 | } | ||
389 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data(ds->pos->meta); | ||
390 | ds->pos = advance(ds->pos); | ||
391 | return GNUNET_OK; | ||
392 | } | ||
393 | |||
394 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: | ||
395 | if (NULL != ds->pos) | ||
396 | { | ||
397 | GNUNET_break(0); | ||
398 | break; | ||
399 | } | ||
400 | if (0 != left) | ||
401 | { | ||
402 | GNUNET_break(0); | ||
403 | break; | 374 | break; |
404 | } | 375 | } |
405 | if (NULL == ds->toplevel) | 376 | /* having full filenames is too dangerous; always make sure we clean them up */ |
406 | break; | 377 | GNUNET_CONTAINER_meta_data_delete (ds->pos->meta, |
407 | ds->stop_task = GNUNET_SCHEDULER_add_now(&finish_scan, ds); | 378 | EXTRACTOR_METATYPE_FILENAME, |
379 | NULL, | ||
380 | 0); | ||
381 | /* instead, put in our 'safer' original filename */ | ||
382 | GNUNET_CONTAINER_meta_data_insert (ds->pos->meta, | ||
383 | "<libgnunetfs>", | ||
384 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, | ||
385 | EXTRACTOR_METAFORMAT_UTF8, | ||
386 | "text/plain", | ||
387 | ds->pos->short_filename, | ||
388 | strlen (ds->pos->short_filename) | ||
389 | + 1); | ||
390 | } | ||
391 | ds->pos->ksk_uri = GNUNET_FS_uri_ksk_create_from_meta_data ( | ||
392 | ds->pos->meta); | ||
393 | ds->pos = advance (ds->pos); | ||
408 | return GNUNET_OK; | 394 | return GNUNET_OK; |
395 | } | ||
409 | 396 | ||
410 | default: | 397 | case GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED: |
411 | GNUNET_break(0); | 398 | if (NULL != ds->pos) |
399 | { | ||
400 | GNUNET_break (0); | ||
401 | break; | ||
402 | } | ||
403 | if (0 != left) | ||
404 | { | ||
405 | GNUNET_break (0); | ||
412 | break; | 406 | break; |
413 | } | 407 | } |
414 | ds->progress_callback(ds->progress_callback_cls, | 408 | if (NULL == ds->toplevel) |
415 | NULL, | 409 | break; |
416 | GNUNET_SYSERR, | 410 | ds->stop_task = GNUNET_SCHEDULER_add_now (&finish_scan, ds); |
417 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 411 | return GNUNET_OK; |
412 | |||
413 | default: | ||
414 | GNUNET_break (0); | ||
415 | break; | ||
416 | } | ||
417 | ds->progress_callback (ds->progress_callback_cls, | ||
418 | NULL, | ||
419 | GNUNET_SYSERR, | ||
420 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | ||
418 | return GNUNET_OK; | 421 | return GNUNET_OK; |
419 | } | 422 | } |
420 | 423 | ||
@@ -425,17 +428,17 @@ process_helper_msgs(void *cls, const struct GNUNET_MessageHeader *msg) | |||
425 | * @param cls the 'struct GNUNET_FS_DirScanner' callback. | 428 | * @param cls the 'struct GNUNET_FS_DirScanner' callback. |
426 | */ | 429 | */ |
427 | static void | 430 | static void |
428 | helper_died_cb(void *cls) | 431 | helper_died_cb (void *cls) |
429 | { | 432 | { |
430 | struct GNUNET_FS_DirScanner *ds = cls; | 433 | struct GNUNET_FS_DirScanner *ds = cls; |
431 | 434 | ||
432 | ds->helper = NULL; | 435 | ds->helper = NULL; |
433 | if (NULL != ds->stop_task) | 436 | if (NULL != ds->stop_task) |
434 | return; /* normal death, was finished */ | 437 | return; /* normal death, was finished */ |
435 | ds->progress_callback(ds->progress_callback_cls, | 438 | ds->progress_callback (ds->progress_callback_cls, |
436 | NULL, | 439 | NULL, |
437 | GNUNET_SYSERR, | 440 | GNUNET_SYSERR, |
438 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); | 441 | GNUNET_FS_DIRSCANNER_INTERNAL_ERROR); |
439 | } | 442 | } |
440 | 443 | ||
441 | 444 | ||
@@ -451,48 +454,48 @@ helper_died_cb(void *cls) | |||
451 | * @return directory scanner object to be used for controlling the scanner | 454 | * @return directory scanner object to be used for controlling the scanner |
452 | */ | 455 | */ |
453 | struct GNUNET_FS_DirScanner * | 456 | struct GNUNET_FS_DirScanner * |
454 | GNUNET_FS_directory_scan_start(const char *filename, | 457 | GNUNET_FS_directory_scan_start (const char *filename, |
455 | int disable_extractor, | 458 | int disable_extractor, |
456 | const char *ex, | 459 | const char *ex, |
457 | GNUNET_FS_DirScannerProgressCallback cb, | 460 | GNUNET_FS_DirScannerProgressCallback cb, |
458 | void *cb_cls) | 461 | void *cb_cls) |
459 | { | 462 | { |
460 | struct stat sbuf; | 463 | struct stat sbuf; |
461 | char *filename_expanded; | 464 | char *filename_expanded; |
462 | struct GNUNET_FS_DirScanner *ds; | 465 | struct GNUNET_FS_DirScanner *ds; |
463 | 466 | ||
464 | if (0 != stat(filename, &sbuf)) | 467 | if (0 != stat (filename, &sbuf)) |
465 | return NULL; | 468 | return NULL; |
466 | filename_expanded = GNUNET_STRINGS_filename_expand(filename); | 469 | filename_expanded = GNUNET_STRINGS_filename_expand (filename); |
467 | if (NULL == filename_expanded) | 470 | if (NULL == filename_expanded) |
468 | return NULL; | 471 | return NULL; |
469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
470 | "Starting to scan directory `%s'\n", | 473 | "Starting to scan directory `%s'\n", |
471 | filename_expanded); | 474 | filename_expanded); |
472 | ds = GNUNET_new(struct GNUNET_FS_DirScanner); | 475 | ds = GNUNET_new (struct GNUNET_FS_DirScanner); |
473 | ds->progress_callback = cb; | 476 | ds->progress_callback = cb; |
474 | ds->progress_callback_cls = cb_cls; | 477 | ds->progress_callback_cls = cb_cls; |
475 | ds->filename_expanded = filename_expanded; | 478 | ds->filename_expanded = filename_expanded; |
476 | if (disable_extractor) | 479 | if (disable_extractor) |
477 | ds->ex_arg = GNUNET_strdup("-"); | 480 | ds->ex_arg = GNUNET_strdup ("-"); |
478 | else | 481 | else |
479 | ds->ex_arg = (NULL != ex) ? GNUNET_strdup(ex) : NULL; | 482 | ds->ex_arg = (NULL != ex) ? GNUNET_strdup (ex) : NULL; |
480 | ds->args[0] = "gnunet-helper-fs-publish"; | 483 | ds->args[0] = "gnunet-helper-fs-publish"; |
481 | ds->args[1] = ds->filename_expanded; | 484 | ds->args[1] = ds->filename_expanded; |
482 | ds->args[2] = ds->ex_arg; | 485 | ds->args[2] = ds->ex_arg; |
483 | ds->args[3] = NULL; | 486 | ds->args[3] = NULL; |
484 | ds->helper = GNUNET_HELPER_start(GNUNET_NO, | 487 | ds->helper = GNUNET_HELPER_start (GNUNET_NO, |
485 | "gnunet-helper-fs-publish", | 488 | "gnunet-helper-fs-publish", |
486 | ds->args, | 489 | ds->args, |
487 | &process_helper_msgs, | 490 | &process_helper_msgs, |
488 | &helper_died_cb, | 491 | &helper_died_cb, |
489 | ds); | 492 | ds); |
490 | if (NULL == ds->helper) | 493 | if (NULL == ds->helper) |
491 | { | 494 | { |
492 | GNUNET_free(filename_expanded); | 495 | GNUNET_free (filename_expanded); |
493 | GNUNET_free(ds); | 496 | GNUNET_free (ds); |
494 | return NULL; | 497 | return NULL; |
495 | } | 498 | } |
496 | return ds; | 499 | return ds; |
497 | } | 500 | } |
498 | 501 | ||