diff options
Diffstat (limited to 'src/fs/gnunet-helper-fs-publish.c')
-rw-r--r-- | src/fs/gnunet-helper-fs-publish.c | 382 |
1 files changed, 192 insertions, 190 deletions
diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c index a6776d84f..fb5f7497d 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * A node of a directory tree. | 34 | * A node of a directory tree. |
35 | */ | 35 | */ |
36 | struct ScanTreeNode { | 36 | struct ScanTreeNode |
37 | { | ||
37 | /** | 38 | /** |
38 | * This is a doubly-linked list | 39 | * This is a doubly-linked list |
39 | */ | 40 | */ |
@@ -111,41 +112,41 @@ static int output_stream; | |||
111 | * @return always 0 to continue extracting | 112 | * @return always 0 to continue extracting |
112 | */ | 113 | */ |
113 | static int | 114 | static int |
114 | add_to_md(void *cls, | 115 | add_to_md (void *cls, |
115 | const char *plugin_name, | 116 | const char *plugin_name, |
116 | enum EXTRACTOR_MetaType type, | 117 | enum EXTRACTOR_MetaType type, |
117 | enum EXTRACTOR_MetaFormat format, | 118 | enum EXTRACTOR_MetaFormat format, |
118 | const char *data_mime_type, | 119 | const char *data_mime_type, |
119 | const char *data, | 120 | const char *data, |
120 | size_t data_len) | 121 | size_t data_len) |
121 | { | 122 | { |
122 | struct GNUNET_CONTAINER_MetaData *md = cls; | 123 | struct GNUNET_CONTAINER_MetaData *md = cls; |
123 | 124 | ||
124 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || | 125 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || |
125 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && | 126 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && |
126 | ('\0' != data[data_len - 1])) | 127 | ('\0' != data[data_len - 1])) |
127 | { | 128 | { |
128 | char zdata[data_len + 1]; | 129 | char zdata[data_len + 1]; |
129 | GNUNET_memcpy(zdata, data, data_len); | 130 | GNUNET_memcpy (zdata, data, data_len); |
130 | zdata[data_len] = '\0'; | 131 | zdata[data_len] = '\0'; |
131 | (void)GNUNET_CONTAINER_meta_data_insert(md, | 132 | (void) GNUNET_CONTAINER_meta_data_insert (md, |
132 | plugin_name, | 133 | plugin_name, |
133 | type, | 134 | type, |
134 | format, | 135 | format, |
135 | data_mime_type, | 136 | data_mime_type, |
136 | zdata, | 137 | zdata, |
137 | data_len + 1); | 138 | data_len + 1); |
138 | } | 139 | } |
139 | else | 140 | else |
140 | { | 141 | { |
141 | (void)GNUNET_CONTAINER_meta_data_insert(md, | 142 | (void) GNUNET_CONTAINER_meta_data_insert (md, |
142 | plugin_name, | 143 | plugin_name, |
143 | type, | 144 | type, |
144 | format, | 145 | format, |
145 | data_mime_type, | 146 | data_mime_type, |
146 | data, | 147 | data, |
147 | data_len); | 148 | data_len); |
148 | } | 149 | } |
149 | return 0; | 150 | return 0; |
150 | } | 151 | } |
151 | #endif | 152 | #endif |
@@ -157,18 +158,18 @@ add_to_md(void *cls, | |||
157 | * @param tree tree to free | 158 | * @param tree tree to free |
158 | */ | 159 | */ |
159 | static void | 160 | static void |
160 | free_tree(struct ScanTreeNode *tree) | 161 | free_tree (struct ScanTreeNode *tree) |
161 | { | 162 | { |
162 | struct ScanTreeNode *pos; | 163 | struct ScanTreeNode *pos; |
163 | 164 | ||
164 | while (NULL != (pos = tree->children_head)) | 165 | while (NULL != (pos = tree->children_head)) |
165 | free_tree(pos); | 166 | free_tree (pos); |
166 | if (NULL != tree->parent) | 167 | if (NULL != tree->parent) |
167 | GNUNET_CONTAINER_DLL_remove(tree->parent->children_head, | 168 | GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, |
168 | tree->parent->children_tail, | 169 | tree->parent->children_tail, |
169 | tree); | 170 | tree); |
170 | GNUNET_free(tree->filename); | 171 | GNUNET_free (tree->filename); |
171 | GNUNET_free(tree); | 172 | GNUNET_free (tree); |
172 | } | 173 | } |
173 | 174 | ||
174 | 175 | ||
@@ -180,7 +181,7 @@ free_tree(struct ScanTreeNode *tree) | |||
180 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 181 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
181 | */ | 182 | */ |
182 | static int | 183 | static int |
183 | write_all(const void *buf, size_t size) | 184 | write_all (const void *buf, size_t size) |
184 | { | 185 | { |
185 | const char *cbuf = buf; | 186 | const char *cbuf = buf; |
186 | size_t total; | 187 | size_t total; |
@@ -188,16 +189,16 @@ write_all(const void *buf, size_t size) | |||
188 | 189 | ||
189 | total = 0; | 190 | total = 0; |
190 | do | 191 | do |
191 | { | 192 | { |
192 | wr = write(output_stream, &cbuf[total], size - total); | 193 | wr = write (output_stream, &cbuf[total], size - total); |
193 | if (wr > 0) | 194 | if (wr > 0) |
194 | total += wr; | 195 | total += wr; |
195 | } | 196 | } |
196 | while ((wr > 0) && (total < size)); | 197 | while ((wr > 0) && (total < size)); |
197 | if (wr <= 0) | 198 | if (wr <= 0) |
198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
199 | "Failed to write to stdout: %s\n", | 200 | "Failed to write to stdout: %s\n", |
200 | strerror(errno)); | 201 | strerror (errno)); |
201 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; | 202 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; |
202 | } | 203 | } |
203 | 204 | ||
@@ -211,20 +212,20 @@ write_all(const void *buf, size_t size) | |||
211 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) | 212 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) |
212 | */ | 213 | */ |
213 | static int | 214 | static int |
214 | write_message(uint16_t message_type, const char *data, size_t data_length) | 215 | write_message (uint16_t message_type, const char *data, size_t data_length) |
215 | { | 216 | { |
216 | struct GNUNET_MessageHeader hdr; | 217 | struct GNUNET_MessageHeader hdr; |
217 | 218 | ||
218 | #if 0 | 219 | #if 0 |
219 | fprintf(stderr, | 220 | fprintf (stderr, |
220 | "Helper sends %u-byte message of type %u\n", | 221 | "Helper sends %u-byte message of type %u\n", |
221 | (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length), | 222 | (unsigned int) (sizeof(struct GNUNET_MessageHeader) + data_length), |
222 | (unsigned int)message_type); | 223 | (unsigned int) message_type); |
223 | #endif | 224 | #endif |
224 | hdr.type = htons(message_type); | 225 | hdr.type = htons (message_type); |
225 | hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length); | 226 | hdr.size = htons (sizeof(struct GNUNET_MessageHeader) + data_length); |
226 | if ((GNUNET_OK != write_all(&hdr, sizeof(hdr))) || | 227 | if ((GNUNET_OK != write_all (&hdr, sizeof(hdr))) || |
227 | (GNUNET_OK != write_all(data, data_length))) | 228 | (GNUNET_OK != write_all (data, data_length))) |
228 | return GNUNET_SYSERR; | 229 | return GNUNET_SYSERR; |
229 | return GNUNET_OK; | 230 | return GNUNET_OK; |
230 | } | 231 | } |
@@ -241,13 +242,14 @@ write_message(uint16_t message_type, const char *data, size_t data_length) | |||
241 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 242 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
242 | */ | 243 | */ |
243 | static int | 244 | static int |
244 | preprocess_file(const char *filename, struct ScanTreeNode **dst); | 245 | preprocess_file (const char *filename, struct ScanTreeNode **dst); |
245 | 246 | ||
246 | 247 | ||
247 | /** | 248 | /** |
248 | * Closure for the 'scan_callback' | 249 | * Closure for the 'scan_callback' |
249 | */ | 250 | */ |
250 | struct RecursionContext { | 251 | struct RecursionContext |
252 | { | ||
251 | /** | 253 | /** |
252 | * Parent to add the files to. | 254 | * Parent to add the files to. |
253 | */ | 255 | */ |
@@ -270,22 +272,22 @@ struct RecursionContext { | |||
270 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 272 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
271 | */ | 273 | */ |
272 | static int | 274 | static int |
273 | scan_callback(void *cls, const char *filename) | 275 | scan_callback (void *cls, const char *filename) |
274 | { | 276 | { |
275 | struct RecursionContext *rc = cls; | 277 | struct RecursionContext *rc = cls; |
276 | struct ScanTreeNode *chld; | 278 | struct ScanTreeNode *chld; |
277 | 279 | ||
278 | if (GNUNET_OK != preprocess_file(filename, &chld)) | 280 | if (GNUNET_OK != preprocess_file (filename, &chld)) |
279 | { | 281 | { |
280 | rc->stop = GNUNET_YES; | 282 | rc->stop = GNUNET_YES; |
281 | return GNUNET_SYSERR; | 283 | return GNUNET_SYSERR; |
282 | } | 284 | } |
283 | if (NULL == chld) | 285 | if (NULL == chld) |
284 | return GNUNET_OK; | 286 | return GNUNET_OK; |
285 | chld->parent = rc->parent; | 287 | chld->parent = rc->parent; |
286 | GNUNET_CONTAINER_DLL_insert(rc->parent->children_head, | 288 | GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, |
287 | rc->parent->children_tail, | 289 | rc->parent->children_tail, |
288 | chld); | 290 | chld); |
289 | return GNUNET_OK; | 291 | return GNUNET_OK; |
290 | } | 292 | } |
291 | 293 | ||
@@ -301,60 +303,60 @@ scan_callback(void *cls, const char *filename) | |||
301 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 303 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
302 | */ | 304 | */ |
303 | static int | 305 | static int |
304 | preprocess_file(const char *filename, struct ScanTreeNode **dst) | 306 | preprocess_file (const char *filename, struct ScanTreeNode **dst) |
305 | { | 307 | { |
306 | struct ScanTreeNode *item; | 308 | struct ScanTreeNode *item; |
307 | struct stat sbuf; | 309 | struct stat sbuf; |
308 | uint64_t fsize = 0; | 310 | uint64_t fsize = 0; |
309 | 311 | ||
310 | if ((0 != stat(filename, &sbuf)) || | 312 | if ((0 != stat (filename, &sbuf)) || |
311 | ((!S_ISDIR(sbuf.st_mode)) && | 313 | ((! S_ISDIR (sbuf.st_mode)) && |
312 | (GNUNET_OK != | 314 | (GNUNET_OK != |
313 | GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)))) | 315 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) |
314 | { | 316 | { |
315 | /* If the file doesn't exist (or is not stat-able for any other reason) | 317 | /* If the file doesn't exist (or is not stat-able for any other reason) |
316 | skip it (but report it), but do continue. */ | 318 | skip it (but report it), but do continue. */ |
317 | if (GNUNET_OK != | 319 | if (GNUNET_OK != |
318 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, | 320 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, |
319 | filename, | 321 | filename, |
320 | strlen(filename) + 1)) | 322 | strlen (filename) + 1)) |
321 | return GNUNET_SYSERR; | 323 | return GNUNET_SYSERR; |
322 | /* recoverable error, store 'NULL' in *dst */ | 324 | /* recoverable error, store 'NULL' in *dst */ |
323 | *dst = NULL; | 325 | *dst = NULL; |
324 | return GNUNET_OK; | 326 | return GNUNET_OK; |
325 | } | 327 | } |
326 | 328 | ||
327 | /* Report the progress */ | 329 | /* Report the progress */ |
328 | if ( | 330 | if ( |
329 | GNUNET_OK != | 331 | GNUNET_OK != |
330 | write_message(S_ISDIR(sbuf.st_mode) | 332 | write_message (S_ISDIR (sbuf.st_mode) |
331 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY | 333 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY |
332 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, | 334 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, |
333 | filename, | 335 | filename, |
334 | strlen(filename) + 1)) | 336 | strlen (filename) + 1)) |
335 | return GNUNET_SYSERR; | 337 | return GNUNET_SYSERR; |
336 | item = GNUNET_new(struct ScanTreeNode); | 338 | item = GNUNET_new (struct ScanTreeNode); |
337 | item->filename = GNUNET_strdup(filename); | 339 | item->filename = GNUNET_strdup (filename); |
338 | item->is_directory = (S_ISDIR(sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; | 340 | item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; |
339 | item->file_size = fsize; | 341 | item->file_size = fsize; |
340 | if (GNUNET_YES == item->is_directory) | 342 | if (GNUNET_YES == item->is_directory) |
343 | { | ||
344 | struct RecursionContext rc; | ||
345 | |||
346 | rc.parent = item; | ||
347 | rc.stop = GNUNET_NO; | ||
348 | GNUNET_DISK_directory_scan (filename, &scan_callback, &rc); | ||
349 | if ( | ||
350 | (GNUNET_YES == rc.stop) || | ||
351 | (GNUNET_OK != | ||
352 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | ||
353 | "..", | ||
354 | 3))) | ||
341 | { | 355 | { |
342 | struct RecursionContext rc; | 356 | free_tree (item); |
343 | 357 | return GNUNET_SYSERR; | |
344 | rc.parent = item; | ||
345 | rc.stop = GNUNET_NO; | ||
346 | GNUNET_DISK_directory_scan(filename, &scan_callback, &rc); | ||
347 | if ( | ||
348 | (GNUNET_YES == rc.stop) || | ||
349 | (GNUNET_OK != | ||
350 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | ||
351 | "..", | ||
352 | 3))) | ||
353 | { | ||
354 | free_tree(item); | ||
355 | return GNUNET_SYSERR; | ||
356 | } | ||
357 | } | 358 | } |
359 | } | ||
358 | *dst = item; | 360 | *dst = item; |
359 | return GNUNET_OK; | 361 | return GNUNET_OK; |
360 | } | 362 | } |
@@ -367,67 +369,67 @@ preprocess_file(const char *filename, struct ScanTreeNode **dst) | |||
367 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors | 369 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors |
368 | */ | 370 | */ |
369 | static int | 371 | static int |
370 | extract_files(struct ScanTreeNode *item) | 372 | extract_files (struct ScanTreeNode *item) |
371 | { | 373 | { |
372 | struct GNUNET_CONTAINER_MetaData *meta; | 374 | struct GNUNET_CONTAINER_MetaData *meta; |
373 | ssize_t size; | 375 | ssize_t size; |
374 | size_t slen; | 376 | size_t slen; |
375 | 377 | ||
376 | if (GNUNET_YES == item->is_directory) | 378 | if (GNUNET_YES == item->is_directory) |
377 | { | 379 | { |
378 | /* for directories, we simply only descent, no extraction, no | 380 | /* for directories, we simply only descent, no extraction, no |
379 | progress reporting */ | 381 | progress reporting */ |
380 | struct ScanTreeNode *pos; | 382 | struct ScanTreeNode *pos; |
381 | 383 | ||
382 | for (pos = item->children_head; NULL != pos; pos = pos->next) | 384 | for (pos = item->children_head; NULL != pos; pos = pos->next) |
383 | if (GNUNET_OK != extract_files(pos)) | 385 | if (GNUNET_OK != extract_files (pos)) |
384 | return GNUNET_SYSERR; | 386 | return GNUNET_SYSERR; |
385 | return GNUNET_OK; | 387 | return GNUNET_OK; |
386 | } | 388 | } |
387 | 389 | ||
388 | /* this is the expensive operation, *afterwards* we'll check for aborts */ | 390 | /* this is the expensive operation, *afterwards* we'll check for aborts */ |
389 | meta = GNUNET_CONTAINER_meta_data_create(); | 391 | meta = GNUNET_CONTAINER_meta_data_create (); |
390 | #if HAVE_LIBEXTRACTOR | 392 | #if HAVE_LIBEXTRACTOR |
391 | EXTRACTOR_extract(plugins, item->filename, NULL, 0, &add_to_md, meta); | 393 | EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); |
392 | #endif | 394 | #endif |
393 | slen = strlen(item->filename) + 1; | 395 | slen = strlen (item->filename) + 1; |
394 | size = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); | 396 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); |
395 | if (-1 == size) | 397 | if (-1 == size) |
396 | { | 398 | { |
397 | /* no meta data */ | 399 | /* no meta data */ |
398 | GNUNET_CONTAINER_meta_data_destroy(meta); | 400 | GNUNET_CONTAINER_meta_data_destroy (meta); |
399 | if (GNUNET_OK != | 401 | if (GNUNET_OK != |
400 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 402 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
401 | item->filename, | 403 | item->filename, |
402 | slen)) | 404 | slen)) |
403 | return GNUNET_SYSERR; | 405 | return GNUNET_SYSERR; |
404 | return GNUNET_OK; | 406 | return GNUNET_OK; |
405 | } | 407 | } |
406 | else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) | 408 | else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) |
407 | { | 409 | { |
408 | /* We can't transfer more than 64k bytes in one message. */ | 410 | /* We can't transfer more than 64k bytes in one message. */ |
409 | size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; | 411 | size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; |
410 | } | 412 | } |
411 | { | 413 | { |
412 | char buf[size + slen]; | 414 | char buf[size + slen]; |
413 | char *dst = &buf[slen]; | 415 | char *dst = &buf[slen]; |
414 | 416 | ||
415 | GNUNET_memcpy(buf, item->filename, slen); | 417 | GNUNET_memcpy (buf, item->filename, slen); |
416 | size = GNUNET_CONTAINER_meta_data_serialize( | 418 | size = GNUNET_CONTAINER_meta_data_serialize ( |
417 | meta, | 419 | meta, |
418 | &dst, | 420 | &dst, |
419 | size, | 421 | size, |
420 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 422 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
421 | if (size < 0) | 423 | if (size < 0) |
422 | { | 424 | { |
423 | GNUNET_break(0); | 425 | GNUNET_break (0); |
424 | size = 0; | 426 | size = 0; |
425 | } | 427 | } |
426 | GNUNET_CONTAINER_meta_data_destroy(meta); | 428 | GNUNET_CONTAINER_meta_data_destroy (meta); |
427 | if (GNUNET_OK != | 429 | if (GNUNET_OK != |
428 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 430 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
429 | buf, | 431 | buf, |
430 | slen + size)) | 432 | slen + size)) |
431 | return GNUNET_SYSERR; | 433 | return GNUNET_SYSERR; |
432 | } | 434 | } |
433 | return GNUNET_OK; | 435 | return GNUNET_OK; |
@@ -438,23 +440,23 @@ extract_files(struct ScanTreeNode *item) | |||
438 | * Install a signal handler to ignore SIGPIPE. | 440 | * Install a signal handler to ignore SIGPIPE. |
439 | */ | 441 | */ |
440 | static void | 442 | static void |
441 | ignore_sigpipe() | 443 | ignore_sigpipe () |
442 | { | 444 | { |
443 | struct sigaction oldsig; | 445 | struct sigaction oldsig; |
444 | struct sigaction sig; | 446 | struct sigaction sig; |
445 | 447 | ||
446 | memset(&sig, 0, sizeof(struct sigaction)); | 448 | memset (&sig, 0, sizeof(struct sigaction)); |
447 | sig.sa_handler = SIG_IGN; | 449 | sig.sa_handler = SIG_IGN; |
448 | sigemptyset(&sig.sa_mask); | 450 | sigemptyset (&sig.sa_mask); |
449 | #ifdef SA_INTERRUPT | 451 | #ifdef SA_INTERRUPT |
450 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | 452 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ |
451 | #else | 453 | #else |
452 | sig.sa_flags = SA_RESTART; | 454 | sig.sa_flags = SA_RESTART; |
453 | #endif | 455 | #endif |
454 | if (0 != sigaction(SIGPIPE, &sig, &oldsig)) | 456 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) |
455 | fprintf(stderr, | 457 | fprintf (stderr, |
456 | "Failed to install SIGPIPE handler: %s\n", | 458 | "Failed to install SIGPIPE handler: %s\n", |
457 | strerror(errno)); | 459 | strerror (errno)); |
458 | } | 460 | } |
459 | 461 | ||
460 | 462 | ||
@@ -465,17 +467,17 @@ ignore_sigpipe() | |||
465 | * @param flags flags to use (O_RDONLY or O_WRONLY) | 467 | * @param flags flags to use (O_RDONLY or O_WRONLY) |
466 | */ | 468 | */ |
467 | static void | 469 | static void |
468 | make_dev_zero(int fd, int flags) | 470 | make_dev_zero (int fd, int flags) |
469 | { | 471 | { |
470 | int z; | 472 | int z; |
471 | 473 | ||
472 | GNUNET_assert(0 == close(fd)); | 474 | GNUNET_assert (0 == close (fd)); |
473 | z = open("/dev/null", flags); | 475 | z = open ("/dev/null", flags); |
474 | GNUNET_assert(-1 != z); | 476 | GNUNET_assert (-1 != z); |
475 | if (z == fd) | 477 | if (z == fd) |
476 | return; | 478 | return; |
477 | GNUNET_break(fd == dup2(z, fd)); | 479 | GNUNET_break (fd == dup2 (z, fd)); |
478 | GNUNET_assert(0 == close(z)); | 480 | GNUNET_assert (0 == close (z)); |
479 | } | 481 | } |
480 | 482 | ||
481 | 483 | ||
@@ -490,82 +492,82 @@ make_dev_zero(int fd, int flags) | |||
490 | * @return 0 on success | 492 | * @return 0 on success |
491 | */ | 493 | */ |
492 | int | 494 | int |
493 | main(int argc, char *const *argv) | 495 | main (int argc, char *const *argv) |
494 | { | 496 | { |
495 | const char *filename_expanded; | 497 | const char *filename_expanded; |
496 | const char *ex; | 498 | const char *ex; |
497 | struct ScanTreeNode *root; | 499 | struct ScanTreeNode *root; |
498 | 500 | ||
499 | ignore_sigpipe(); | 501 | ignore_sigpipe (); |
500 | /* move stdout to some other FD for IPC, bind | 502 | /* move stdout to some other FD for IPC, bind |
501 | stdout/stderr to /dev/null */ | 503 | stdout/stderr to /dev/null */ |
502 | output_stream = dup(1); | 504 | output_stream = dup (1); |
503 | make_dev_zero(1, O_WRONLY); | 505 | make_dev_zero (1, O_WRONLY); |
504 | make_dev_zero(2, O_WRONLY); | 506 | make_dev_zero (2, O_WRONLY); |
505 | 507 | ||
506 | /* parse command line */ | 508 | /* parse command line */ |
507 | if ((3 != argc) && (2 != argc)) | 509 | if ((3 != argc) && (2 != argc)) |
508 | { | 510 | { |
509 | fprintf(stderr, | 511 | fprintf (stderr, |
510 | "%s", | 512 | "%s", |
511 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); | 513 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); |
512 | return 1; | 514 | return 1; |
513 | } | 515 | } |
514 | filename_expanded = argv[1]; | 516 | filename_expanded = argv[1]; |
515 | ex = argv[2]; | 517 | ex = argv[2]; |
516 | if ((NULL == ex) || (0 != strcmp(ex, "-"))) | 518 | if ((NULL == ex) || (0 != strcmp (ex, "-"))) |
517 | { | 519 | { |
518 | #if HAVE_LIBEXTRACTOR | 520 | #if HAVE_LIBEXTRACTOR |
519 | plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); | 521 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); |
520 | if (NULL != ex) | 522 | if (NULL != ex) |
521 | plugins = EXTRACTOR_plugin_add_config(plugins, | 523 | plugins = EXTRACTOR_plugin_add_config (plugins, |
522 | ex, | 524 | ex, |
523 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 525 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
524 | #endif | 526 | #endif |
525 | } | 527 | } |
526 | 528 | ||
527 | /* scan tree to find out how much work there is to be done */ | 529 | /* scan tree to find out how much work there is to be done */ |
528 | if (GNUNET_OK != preprocess_file(filename_expanded, &root)) | 530 | if (GNUNET_OK != preprocess_file (filename_expanded, &root)) |
529 | { | 531 | { |
530 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); | 532 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); |
531 | #if HAVE_LIBEXTRACTOR | 533 | #if HAVE_LIBEXTRACTOR |
532 | EXTRACTOR_plugin_remove_all(plugins); | 534 | EXTRACTOR_plugin_remove_all (plugins); |
533 | #endif | 535 | #endif |
534 | return 2; | 536 | return 2; |
535 | } | 537 | } |
536 | /* signal that we're done counting files, so that a percentage of | 538 | /* signal that we're done counting files, so that a percentage of |
537 | progress can now be calculated */ | 539 | progress can now be calculated */ |
538 | if (GNUNET_OK != | 540 | if (GNUNET_OK != |
539 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, | 541 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, |
540 | NULL, | 542 | NULL, |
541 | 0)) | 543 | 0)) |
542 | { | 544 | { |
543 | #if HAVE_LIBEXTRACTOR | 545 | #if HAVE_LIBEXTRACTOR |
544 | EXTRACTOR_plugin_remove_all(plugins); | 546 | EXTRACTOR_plugin_remove_all (plugins); |
545 | #endif | 547 | #endif |
546 | return 3; | 548 | return 3; |
547 | } | 549 | } |
548 | if (NULL != root) | 550 | if (NULL != root) |
551 | { | ||
552 | if (GNUNET_OK != extract_files (root)) | ||
549 | { | 553 | { |
550 | if (GNUNET_OK != extract_files(root)) | 554 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, |
551 | { | 555 | NULL, |
552 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, | 556 | 0); |
553 | NULL, | 557 | free_tree (root); |
554 | 0); | ||
555 | free_tree(root); | ||
556 | #if HAVE_LIBEXTRACTOR | 558 | #if HAVE_LIBEXTRACTOR |
557 | EXTRACTOR_plugin_remove_all(plugins); | 559 | EXTRACTOR_plugin_remove_all (plugins); |
558 | #endif | 560 | #endif |
559 | return 4; | 561 | return 4; |
560 | } | ||
561 | free_tree(root); | ||
562 | } | 562 | } |
563 | free_tree (root); | ||
564 | } | ||
563 | /* enable "clean" shutdown by telling parent that we are done */ | 565 | /* enable "clean" shutdown by telling parent that we are done */ |
564 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, | 566 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, |
565 | NULL, | 567 | NULL, |
566 | 0); | 568 | 0); |
567 | #if HAVE_LIBEXTRACTOR | 569 | #if HAVE_LIBEXTRACTOR |
568 | EXTRACTOR_plugin_remove_all(plugins); | 570 | EXTRACTOR_plugin_remove_all (plugins); |
569 | #endif | 571 | #endif |
570 | return 0; | 572 | return 0; |
571 | } | 573 | } |