diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-11 15:07:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-11 15:07:59 +0000 |
commit | af395c0e26eaa4af5ba4c41494be3357e61e6179 (patch) | |
tree | db665bc1cac30c456192f8a851de3a8f8079e716 /src/peerinfo | |
parent | 21a433bd0d1a4410f6459fe0d59e5a27809bc735 (diff) | |
download | gnunet-af395c0e26eaa4af5ba4c41494be3357e61e6179.tar.gz gnunet-af395c0e26eaa4af5ba4c41494be3357e61e6179.zip |
-avoid duplicate remove
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 2f1e7a3d9..b7fa1c722 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -320,11 +320,13 @@ update_hello (const struct GNUNET_PeerIdentity *peer, | |||
320 | * HELLO should be included | 320 | * HELLO should be included |
321 | * | 321 | * |
322 | * @param fn name of the file | 322 | * @param fn name of the file |
323 | * @param unlink_garbage if GNUNET_YES, try to remove useless files | 323 | * @param unlink_garbage if #GNUNET_YES, try to remove useless files |
324 | * @param r ReadHostFileContext to store the resutl | 324 | * @param r ReadHostFileContext to store the resutl |
325 | */ | 325 | */ |
326 | static void | 326 | static void |
327 | read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext *r) | 327 | read_host_file (const char *fn, |
328 | int unlink_garbage, | ||
329 | struct ReadHostFileContext *r) | ||
328 | { | 330 | { |
329 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; | 331 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; |
330 | unsigned int size_total; | 332 | unsigned int size_total; |
@@ -340,12 +342,12 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
340 | r->hello = NULL; | 342 | r->hello = NULL; |
341 | 343 | ||
342 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) | 344 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) |
343 | { | ||
344 | return; | 345 | return; |
345 | } | ||
346 | |||
347 | size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 346 | size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); |
348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read %u bytes from `%s'\n", size_total, fn); | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
348 | "Read %u bytes from `%s'\n", | ||
349 | size_total, | ||
350 | fn); | ||
349 | if (size_total < sizeof (struct GNUNET_MessageHeader)) | 351 | if (size_total < sizeof (struct GNUNET_MessageHeader)) |
350 | { | 352 | { |
351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -354,7 +356,9 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
354 | if ( (GNUNET_YES == unlink_garbage) && | 356 | if ( (GNUNET_YES == unlink_garbage) && |
355 | (0 != UNLINK (fn)) && | 357 | (0 != UNLINK (fn)) && |
356 | (ENOENT != errno) ) | 358 | (ENOENT != errno) ) |
357 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 359 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
360 | "unlink", | ||
361 | fn); | ||
358 | return; | 362 | return; |
359 | } | 363 | } |
360 | 364 | ||
@@ -367,11 +371,15 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
367 | { | 371 | { |
368 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 372 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
369 | _("Failed to parse HELLO in file `%s': %s %u \n"), | 373 | _("Failed to parse HELLO in file `%s': %s %u \n"), |
370 | fn, "HELLO is invalid and has size of ", size_hello); | 374 | fn, |
375 | "HELLO is invalid and has size of ", | ||
376 | size_hello); | ||
371 | if ((GNUNET_YES == unlink_garbage) && | 377 | if ((GNUNET_YES == unlink_garbage) && |
372 | (0 != UNLINK (fn)) && | 378 | (0 != UNLINK (fn)) && |
373 | (ENOENT != errno) ) | 379 | (ENOENT != errno) ) |
374 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 380 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
381 | "unlink", | ||
382 | fn); | ||
375 | return; | 383 | return; |
376 | } | 384 | } |
377 | 385 | ||
@@ -416,10 +424,12 @@ read_host_file (const char *fn, int unlink_garbage, struct ReadHostFileContext * | |||
416 | if (0 == left) | 424 | if (0 == left) |
417 | { | 425 | { |
418 | /* no addresses left, remove from disk */ | 426 | /* no addresses left, remove from disk */ |
419 | if ((GNUNET_YES == unlink_garbage) && (0 != UNLINK (fn))) | 427 | if ( (GNUNET_YES == unlink_garbage) && |
420 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 428 | (0 != UNLINK (fn)) ) |
429 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
430 | "unlink", | ||
431 | fn); | ||
421 | } | 432 | } |
422 | |||
423 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
424 | "Found `%s' and `%s' HELLO message in file\n", | 434 | "Found `%s' and `%s' HELLO message in file\n", |
425 | (NULL != r->hello) ? "public" : "NO public", | 435 | (NULL != r->hello) ? "public" : "NO public", |
@@ -534,18 +544,13 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
534 | 544 | ||
535 | filename = strrchr (fullname, DIR_SEPARATOR); | 545 | filename = strrchr (fullname, DIR_SEPARATOR); |
536 | if ((NULL == filename) || (1 > strlen (filename))) | 546 | if ((NULL == filename) || (1 > strlen (filename))) |
537 | filename = fullname; | 547 | filename = fullname; |
538 | else | 548 | else |
539 | filename ++; | 549 | filename ++; |
540 | 550 | ||
541 | read_host_file (fullname, dsc->remove_files, &r); | 551 | read_host_file (fullname, dsc->remove_files, &r); |
542 | if ( (NULL == r.hello) && (NULL == r.friend_only_hello)) | 552 | if ( (NULL == r.hello) && (NULL == r.friend_only_hello)) |
543 | { | ||
544 | if (GNUNET_YES == dsc->remove_files) | ||
545 | remove_garbage (fullname); | ||
546 | return GNUNET_OK; | 553 | return GNUNET_OK; |
547 | } | ||
548 | |||
549 | if (NULL != r.friend_only_hello) | 554 | if (NULL != r.friend_only_hello) |
550 | { | 555 | { |
551 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) | 556 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) |