comparison libpurple/core.c @ 18148:f160b6e84d0c

Use dynamicly allocated string manipulation here as well to avoid a MAXPATHLEN. This is untested, as I don't use Zephyr. This also leaks a string at libpurple uninit. If that's bad, I can add a callback to this file and call it from the prpl's unload callback. References #1635
author Richard Laager <rlaager@wiktel.com>
date Sun, 17 Jun 2007 03:00:15 +0000
parents 1d6007400837
children 4cc042912ac2
comparison
equal deleted inserted replaced
18147:5653692dcf79 18148:f160b6e84d0c
487 if (g_file_test(name, G_FILE_TEST_IS_SYMLINK)) 487 if (g_file_test(name, G_FILE_TEST_IS_SYMLINK))
488 { 488 {
489 /* We're only going to duplicate a logs symlink. */ 489 /* We're only going to duplicate a logs symlink. */
490 if (!strcmp(entry, "logs")) 490 if (!strcmp(entry, "logs"))
491 { 491 {
492 char buf[MAXPATHLEN]; 492 char *link;
493 size_t linklen; 493 #if GLIB_CHECK_VERSION(2,4,0)
494 494 GError *err = NULL;
495 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) 495
496 { 496 if ((link = g_file_read_link(name, &err)) == NULL)
497 {
498 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
497 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", 499 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n",
498 name, strerror(errno)); 500 name_utf8 ? name_utf8 : name, err->message);
501 g_free(name_utf8);
502 g_error_free(err);
499 g_free(name); 503 g_free(name);
500 g_dir_close(dir); 504 g_dir_close(dir);
501 g_free(status_file); 505 g_free(status_file);
502 g_free(old_user_dir); 506 g_free(old_user_dir);
503 return FALSE; 507 return FALSE;
504 } 508 }
509 #else
510 char buf[MAXPATHLEN];
511 size_t linklen;
512
513 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1))
514 {
515 char *name_utf8 = g_filename_to_utf8(name);
516 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n",
517 name_utf8, strerror(errno));
518 g_free(name_utf8);
519 g_free(name);
520 g_dir_close(dir);
521 g_free(status_file);
522 g_free(old_user_dir);
523 return FALSE;
524 }
505 buf[linklen] = '\0'; 525 buf[linklen] = '\0';
506 526
507 logs_dir = g_strconcat(user_dir, G_DIR_SEPARATOR_S "logs", NULL); 527 /* This way we don't have to GLIB_VERSION_CHECK every g_free(link) below. */
508 528 link = g_strdup(buf);
509 if (!strcmp(buf, "../.purple/logs") || !strcmp(buf, logs_dir)) 529 #endif
530
531 logs_dir = g_build_filename(user_dir, "logs", NULL);
532
533 if (!strcmp(link, "../.purple/logs") || !strcmp(link, logs_dir))
510 { 534 {
511 /* If the symlink points to the new directory, we're 535 /* If the symlink points to the new directory, we're
512 * likely just trying again after a failed migration, 536 * likely just trying again after a failed migration,
513 * so there's no need to fail here. */ 537 * so there's no need to fail here. */
538 g_free(link);
514 g_free(logs_dir); 539 g_free(logs_dir);
515 continue; 540 continue;
516 } 541 }
517 542
518 /* In case we are trying again after a failed migration, we need 543 /* In case we are trying again after a failed migration, we need
520 * will fail, and so will the symlink below, which is good 545 * will fail, and so will the symlink below, which is good
521 * because the user should sort things out. */ 546 * because the user should sort things out. */
522 g_unlink(logs_dir); 547 g_unlink(logs_dir);
523 548
524 /* Relative links will most likely still be 549 /* Relative links will most likely still be
525 * valid from ~/.purple, though not it's not 550 * valid from ~/.purple, though it's not
526 * guaranteed. Oh well. */ 551 * guaranteed. Oh well. */
527 if (symlink(buf, logs_dir)) 552 if (symlink(link, logs_dir))
528 { 553 {
529 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", 554 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n",
530 logs_dir, buf, strerror(errno)); 555 logs_dir, link, strerror(errno));
556 g_free(link);
531 g_free(name); 557 g_free(name);
532 g_free(logs_dir); 558 g_free(logs_dir);
533 g_dir_close(dir); 559 g_dir_close(dir);
534 g_free(status_file); 560 g_free(status_file);
535 g_free(old_user_dir); 561 g_free(old_user_dir);
536 return FALSE; 562 return FALSE;
537 } 563 }
538 564
565 g_free(link);
539 g_free(logs_dir); 566 g_free(logs_dir);
540 continue; 567 continue;
541 } 568 }
542 569
543 /* Ignore all other symlinks. */ 570 /* Ignore all other symlinks. */