comparison libpurple/core.c @ 24263:e4f4ffd7ed4c

propagate from branch 'im.pidgin.pidgin' (head 4e892c470840f4ed8b012015b15ff8956166028a) to branch 'im.pidgin.pidgin.openq' (head 2dab44421846610c60c31aa1402de99f4001b996)
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 28 Oct 2008 16:59:07 +0000
parents a29ae9a5c311
children a6742d9eadf3 6ebabe0841a0
comparison
equal deleted inserted replaced
24096:cae676ac3c70 24263:e4f4ffd7ed4c
359 #ifndef _WIN32 359 #ifndef _WIN32
360 char *old_name; 360 char *old_name;
361 #endif 361 #endif
362 if (g_rename(path, new_name)) 362 if (g_rename(path, new_name))
363 { 363 {
364 purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at http://developer.pidgin.im\n", 364 purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
365 path, new_name, g_strerror(errno)); 365 path, new_name, g_strerror(errno));
366 g_free(new_name); 366 g_free(new_name);
367 return FALSE; 367 return FALSE;
368 } 368 }
369 g_free(new_name); 369 g_free(new_name);
372 /* NOTE: This new_name is relative. */ 372 /* NOTE: This new_name is relative. */
373 new_name = g_build_filename(relative, basename, NULL); 373 new_name = g_build_filename(relative, basename, NULL);
374 old_name = g_build_filename(old_base, basename, NULL); 374 old_name = g_build_filename(old_base, basename, NULL);
375 if (symlink(new_name, old_name)) 375 if (symlink(new_name, old_name))
376 { 376 {
377 purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", 377 purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
378 old_name, new_name, g_strerror(errno)); 378 old_name, new_name, g_strerror(errno));
379 } 379 }
380 g_free(old_name); 380 g_free(old_name);
381 g_free(new_name); 381 g_free(new_name);
382 #endif 382 #endif
428 /* Ensure the user directory exists */ 428 /* Ensure the user directory exists */
429 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) 429 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR))
430 { 430 {
431 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) 431 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
432 { 432 {
433 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", 433 purple_debug_error("core", "Error creating directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
434 user_dir, g_strerror(errno)); 434 user_dir, g_strerror(errno));
435 g_free(status_file); 435 g_free(status_file);
436 g_free(old_user_dir); 436 g_free(old_user_dir);
437 return FALSE; 437 return FALSE;
438 } 438 }
440 440
441 /* This writes ~/.purple/migrating, which allows us to detect 441 /* This writes ~/.purple/migrating, which allows us to detect
442 * incomplete migrations and properly retry. */ 442 * incomplete migrations and properly retry. */
443 if (!(fp = g_fopen(status_file, "w"))) 443 if (!(fp = g_fopen(status_file, "w")))
444 { 444 {
445 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", 445 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
446 status_file, g_strerror(errno)); 446 status_file, g_strerror(errno));
447 g_free(status_file); 447 g_free(status_file);
448 g_free(old_user_dir); 448 g_free(old_user_dir);
449 return FALSE; 449 return FALSE;
450 } 450 }
452 452
453 /* Open ~/.gaim so we can loop over its contents. */ 453 /* Open ~/.gaim so we can loop over its contents. */
454 err = NULL; 454 err = NULL;
455 if (!(dir = g_dir_open(old_user_dir, 0, &err))) 455 if (!(dir = g_dir_open(old_user_dir, 0, &err)))
456 { 456 {
457 purple_debug_error("core", "Error opening directory %s: %s. Please report this at http://developer.pidgin.im\n", 457 purple_debug_error("core", "Error opening directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
458 status_file, 458 status_file,
459 (err ? err->message : "Unknown error")); 459 (err ? err->message : "Unknown error"));
460 if (err) 460 if (err)
461 g_error_free(err); 461 g_error_free(err);
462 g_free(status_file); 462 g_free(status_file);
481 GError *err = NULL; 481 GError *err = NULL;
482 482
483 if ((link = g_file_read_link(name, &err)) == NULL) 483 if ((link = g_file_read_link(name, &err)) == NULL)
484 { 484 {
485 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); 485 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
486 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", 486 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
487 name_utf8 ? name_utf8 : name, err->message); 487 name_utf8 ? name_utf8 : name, err->message);
488 g_free(name_utf8); 488 g_free(name_utf8);
489 g_error_free(err); 489 g_error_free(err);
490 g_free(name); 490 g_free(name);
491 g_dir_close(dir); 491 g_dir_close(dir);
498 size_t linklen; 498 size_t linklen;
499 499
500 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) 500 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1))
501 { 501 {
502 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); 502 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
503 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", 503 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
504 name_utf8, g_strerror(errno)); 504 name_utf8, g_strerror(errno));
505 g_free(name_utf8); 505 g_free(name_utf8);
506 g_free(name); 506 g_free(name);
507 g_dir_close(dir); 507 g_dir_close(dir);
508 g_free(status_file); 508 g_free(status_file);
536 /* Relative links will most likely still be 536 /* Relative links will most likely still be
537 * valid from ~/.purple, though it's not 537 * valid from ~/.purple, though it's not
538 * guaranteed. Oh well. */ 538 * guaranteed. Oh well. */
539 if (symlink(link, logs_dir)) 539 if (symlink(link, logs_dir))
540 { 540 {
541 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", 541 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
542 logs_dir, link, g_strerror(errno)); 542 logs_dir, link, g_strerror(errno));
543 g_free(link); 543 g_free(link);
544 g_free(name); 544 g_free(name);
545 g_free(logs_dir); 545 g_free(logs_dir);
546 g_dir_close(dir); 546 g_dir_close(dir);
575 const char *icons_entry; 575 const char *icons_entry;
576 576
577 err = NULL; 577 err = NULL;
578 if (!(icons_dir = g_dir_open(name, 0, &err))) 578 if (!(icons_dir = g_dir_open(name, 0, &err)))
579 { 579 {
580 purple_debug_error("core", "Error opening directory %s: %s. Please report this at http://developer.pidgin.im\n", 580 purple_debug_error("core", "Error opening directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
581 name, 581 name,
582 (err ? err->message : "Unknown error")); 582 (err ? err->message : "Unknown error"));
583 if (err) 583 if (err)
584 g_error_free(err); 584 g_error_free(err);
585 g_free(name); 585 g_free(name);
593 /* Ensure the new icon directory exists */ 593 /* Ensure the new icon directory exists */
594 if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR)) 594 if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR))
595 { 595 {
596 if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) 596 if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
597 { 597 {
598 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", 598 purple_debug_error("core", "Error creating directory %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
599 new_icons_dir, g_strerror(errno)); 599 new_icons_dir, g_strerror(errno));
600 g_free(new_icons_dir); 600 g_free(new_icons_dir);
601 g_dir_close(icons_dir); 601 g_dir_close(icons_dir);
602 g_free(name); 602 g_free(name);
603 g_dir_close(dir); 603 g_dir_close(dir);
656 char *new_name; 656 char *new_name;
657 FILE *new_file; 657 FILE *new_file;
658 658
659 if (!(fp = g_fopen(name, "rb"))) 659 if (!(fp = g_fopen(name, "rb")))
660 { 660 {
661 purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at http://developer.pidgin.im\n", 661 purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
662 name, g_strerror(errno)); 662 name, g_strerror(errno));
663 g_free(name); 663 g_free(name);
664 g_dir_close(dir); 664 g_dir_close(dir);
665 g_free(status_file); 665 g_free(status_file);
666 g_free(old_user_dir); 666 g_free(old_user_dir);
668 } 668 }
669 669
670 new_name = g_build_filename(user_dir, entry, NULL); 670 new_name = g_build_filename(user_dir, entry, NULL);
671 if (!(new_file = g_fopen(new_name, "wb"))) 671 if (!(new_file = g_fopen(new_name, "wb")))
672 { 672 {
673 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", 673 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
674 new_name, g_strerror(errno)); 674 new_name, g_strerror(errno));
675 fclose(fp); 675 fclose(fp);
676 g_free(new_name); 676 g_free(new_name);
677 g_free(name); 677 g_free(name);
678 g_dir_close(dir); 678 g_dir_close(dir);
687 size_t size; 687 size_t size;
688 688
689 size = fread(buf, 1, sizeof(buf), fp); 689 size = fread(buf, 1, sizeof(buf), fp);
690 if (size != sizeof(buf) && !feof(fp)) 690 if (size != sizeof(buf) && !feof(fp))
691 { 691 {
692 purple_debug_error("core", "Error reading %s: %s. Please report this at http://developer.pidgin.im\n", 692 purple_debug_error("core", "Error reading %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
693 name, g_strerror(errno)); 693 name, g_strerror(errno));
694 fclose(new_file); 694 fclose(new_file);
695 fclose(fp); 695 fclose(fp);
696 g_free(new_name); 696 g_free(new_name);
697 g_free(name); 697 g_free(name);
701 return FALSE; 701 return FALSE;
702 } 702 }
703 703
704 if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0) 704 if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0)
705 { 705 {
706 purple_debug_error("core", "Error writing %s: %s. Please report this at http://developer.pidgin.im\n", 706 purple_debug_error("core", "Error writing %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
707 new_name, g_strerror(errno)); 707 new_name, g_strerror(errno));
708 fclose(new_file); 708 fclose(new_file);
709 fclose(fp); 709 fclose(fp);
710 g_free(new_name); 710 g_free(new_name);
711 g_free(name); 711 g_free(name);
716 } 716 }
717 } 717 }
718 718
719 if (fclose(new_file)) 719 if (fclose(new_file))
720 { 720 {
721 purple_debug_error("core", "Error writing: %s: %s. Please report this at http://developer.pidgin.im\n", 721 purple_debug_error("core", "Error writing: %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
722 new_name, g_strerror(errno)); 722 new_name, g_strerror(errno));
723 } 723 }
724 if (fclose(fp)) 724 if (fclose(fp))
725 { 725 {
726 purple_debug_warning("core", "Error closing %s: %s\n", 726 purple_debug_warning("core", "Error closing %s: %s\n",
735 } 735 }
736 736
737 /* The migration was successful, so delete the status file. */ 737 /* The migration was successful, so delete the status file. */
738 if (g_unlink(status_file)) 738 if (g_unlink(status_file))
739 { 739 {
740 purple_debug_error("core", "Error unlinking file %s: %s. Please report this at http://developer.pidgin.im\n", 740 purple_debug_error("core", "Error unlinking file %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n",
741 status_file, g_strerror(errno)); 741 status_file, g_strerror(errno));
742 g_free(status_file); 742 g_free(status_file);
743 return FALSE; 743 return FALSE;
744 } 744 }
745 745