comparison libpurple/core.c @ 21284:6de09629f091

propagate from branch 'im.pidgin.pidgin.next.minor' (head 0c9637482b845cc65e95a26e144697391c51133f) to branch 'im.pidgin.pidgin' (head e3a6991e78dac328f13804950fee54dfb8afc3c5)
author Ka-Hing Cheung <khc@hxbc.us>
date Sat, 10 Nov 2007 04:52:20 +0000
parents 5915ad785ee7 35b4f1dc4c8d
children 38cc722159ff
comparison
equal deleted inserted replaced
21283:406aa3be6b32 21284:6de09629f091
381 char *old_name; 381 char *old_name;
382 #endif 382 #endif
383 if (g_rename(path, new_name)) 383 if (g_rename(path, new_name))
384 { 384 {
385 purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at http://developer.pidgin.im\n", 385 purple_debug_error("core", "Error renaming %s to %s: %s. Please report this at http://developer.pidgin.im\n",
386 path, new_name, strerror(errno)); 386 path, new_name, g_strerror(errno));
387 g_free(new_name); 387 g_free(new_name);
388 return FALSE; 388 return FALSE;
389 } 389 }
390 g_free(new_name); 390 g_free(new_name);
391 391
394 new_name = g_build_filename(relative, basename, NULL); 394 new_name = g_build_filename(relative, basename, NULL);
395 old_name = g_build_filename(old_base, basename, NULL); 395 old_name = g_build_filename(old_base, basename, NULL);
396 if (symlink(new_name, old_name)) 396 if (symlink(new_name, old_name))
397 { 397 {
398 purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", 398 purple_debug_warning("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n",
399 old_name, new_name, strerror(errno)); 399 old_name, new_name, g_strerror(errno));
400 } 400 }
401 g_free(old_name); 401 g_free(old_name);
402 g_free(new_name); 402 g_free(new_name);
403 #endif 403 #endif
404 404
450 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR)) 450 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR))
451 { 451 {
452 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) 452 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
453 { 453 {
454 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", 454 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n",
455 user_dir, strerror(errno)); 455 user_dir, g_strerror(errno));
456 g_free(status_file); 456 g_free(status_file);
457 g_free(old_user_dir); 457 g_free(old_user_dir);
458 return FALSE; 458 return FALSE;
459 } 459 }
460 } 460 }
462 /* This writes ~/.purple/migrating, which allows us to detect 462 /* This writes ~/.purple/migrating, which allows us to detect
463 * incomplete migrations and properly retry. */ 463 * incomplete migrations and properly retry. */
464 if (!(fp = g_fopen(status_file, "w"))) 464 if (!(fp = g_fopen(status_file, "w")))
465 { 465 {
466 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", 466 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n",
467 status_file, strerror(errno)); 467 status_file, g_strerror(errno));
468 g_free(status_file); 468 g_free(status_file);
469 g_free(old_user_dir); 469 g_free(old_user_dir);
470 return FALSE; 470 return FALSE;
471 } 471 }
472 fclose(fp); 472 fclose(fp);
520 520
521 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) 521 if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1))
522 { 522 {
523 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); 523 char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL);
524 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n", 524 purple_debug_error("core", "Error reading symlink %s: %s. Please report this at http://developer.pidgin.im\n",
525 name_utf8, strerror(errno)); 525 name_utf8, g_strerror(errno));
526 g_free(name_utf8); 526 g_free(name_utf8);
527 g_free(name); 527 g_free(name);
528 g_dir_close(dir); 528 g_dir_close(dir);
529 g_free(status_file); 529 g_free(status_file);
530 g_free(old_user_dir); 530 g_free(old_user_dir);
558 * valid from ~/.purple, though it's not 558 * valid from ~/.purple, though it's not
559 * guaranteed. Oh well. */ 559 * guaranteed. Oh well. */
560 if (symlink(link, logs_dir)) 560 if (symlink(link, logs_dir))
561 { 561 {
562 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n", 562 purple_debug_error("core", "Error symlinking %s to %s: %s. Please report this at http://developer.pidgin.im\n",
563 logs_dir, link, strerror(errno)); 563 logs_dir, link, g_strerror(errno));
564 g_free(link); 564 g_free(link);
565 g_free(name); 565 g_free(name);
566 g_free(logs_dir); 566 g_free(logs_dir);
567 g_dir_close(dir); 567 g_dir_close(dir);
568 g_free(status_file); 568 g_free(status_file);
615 if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR)) 615 if (!g_file_test(new_icons_dir, G_FILE_TEST_IS_DIR))
616 { 616 {
617 if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1) 617 if (g_mkdir(new_icons_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
618 { 618 {
619 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n", 619 purple_debug_error("core", "Error creating directory %s: %s. Please report this at http://developer.pidgin.im\n",
620 new_icons_dir, strerror(errno)); 620 new_icons_dir, g_strerror(errno));
621 g_free(new_icons_dir); 621 g_free(new_icons_dir);
622 g_dir_close(icons_dir); 622 g_dir_close(icons_dir);
623 g_free(name); 623 g_free(name);
624 g_dir_close(dir); 624 g_dir_close(dir);
625 g_free(status_file); 625 g_free(status_file);
678 FILE *new_file; 678 FILE *new_file;
679 679
680 if (!(fp = g_fopen(name, "rb"))) 680 if (!(fp = g_fopen(name, "rb")))
681 { 681 {
682 purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at http://developer.pidgin.im\n", 682 purple_debug_error("core", "Error opening file %s for reading: %s. Please report this at http://developer.pidgin.im\n",
683 name, strerror(errno)); 683 name, g_strerror(errno));
684 g_free(name); 684 g_free(name);
685 g_dir_close(dir); 685 g_dir_close(dir);
686 g_free(status_file); 686 g_free(status_file);
687 g_free(old_user_dir); 687 g_free(old_user_dir);
688 return FALSE; 688 return FALSE;
690 690
691 new_name = g_build_filename(user_dir, entry, NULL); 691 new_name = g_build_filename(user_dir, entry, NULL);
692 if (!(new_file = g_fopen(new_name, "wb"))) 692 if (!(new_file = g_fopen(new_name, "wb")))
693 { 693 {
694 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n", 694 purple_debug_error("core", "Error opening file %s for writing: %s. Please report this at http://developer.pidgin.im\n",
695 new_name, strerror(errno)); 695 new_name, g_strerror(errno));
696 fclose(fp); 696 fclose(fp);
697 g_free(new_name); 697 g_free(new_name);
698 g_free(name); 698 g_free(name);
699 g_dir_close(dir); 699 g_dir_close(dir);
700 g_free(status_file); 700 g_free(status_file);
709 709
710 size = fread(buf, 1, sizeof(buf), fp); 710 size = fread(buf, 1, sizeof(buf), fp);
711 if (size != sizeof(buf) && !feof(fp)) 711 if (size != sizeof(buf) && !feof(fp))
712 { 712 {
713 purple_debug_error("core", "Error reading %s: %s. Please report this at http://developer.pidgin.im\n", 713 purple_debug_error("core", "Error reading %s: %s. Please report this at http://developer.pidgin.im\n",
714 name, strerror(errno)); 714 name, g_strerror(errno));
715 fclose(new_file); 715 fclose(new_file);
716 fclose(fp); 716 fclose(fp);
717 g_free(new_name); 717 g_free(new_name);
718 g_free(name); 718 g_free(name);
719 g_dir_close(dir); 719 g_dir_close(dir);
723 } 723 }
724 724
725 if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0) 725 if (!fwrite(buf, size, 1, new_file) && ferror(new_file) != 0)
726 { 726 {
727 purple_debug_error("core", "Error writing %s: %s. Please report this at http://developer.pidgin.im\n", 727 purple_debug_error("core", "Error writing %s: %s. Please report this at http://developer.pidgin.im\n",
728 new_name, strerror(errno)); 728 new_name, g_strerror(errno));
729 fclose(new_file); 729 fclose(new_file);
730 fclose(fp); 730 fclose(fp);
731 g_free(new_name); 731 g_free(new_name);
732 g_free(name); 732 g_free(name);
733 g_dir_close(dir); 733 g_dir_close(dir);
738 } 738 }
739 739
740 if (fclose(new_file)) 740 if (fclose(new_file))
741 { 741 {
742 purple_debug_error("core", "Error writing: %s: %s. Please report this at http://developer.pidgin.im\n", 742 purple_debug_error("core", "Error writing: %s: %s. Please report this at http://developer.pidgin.im\n",
743 new_name, strerror(errno)); 743 new_name, g_strerror(errno));
744 } 744 }
745 if (fclose(fp)) 745 if (fclose(fp))
746 { 746 {
747 purple_debug_warning("core", "Error closing %s: %s\n", 747 purple_debug_warning("core", "Error closing %s: %s\n",
748 name, strerror(errno)); 748 name, g_strerror(errno));
749 } 749 }
750 g_free(new_name); 750 g_free(new_name);
751 } 751 }
752 else 752 else
753 purple_debug_warning("core", "Not a regular file or directory: %s\n", name); 753 purple_debug_warning("core", "Not a regular file or directory: %s\n", name);
757 757
758 /* The migration was successful, so delete the status file. */ 758 /* The migration was successful, so delete the status file. */
759 if (g_unlink(status_file)) 759 if (g_unlink(status_file))
760 { 760 {
761 purple_debug_error("core", "Error unlinking file %s: %s. Please report this at http://developer.pidgin.im\n", 761 purple_debug_error("core", "Error unlinking file %s: %s. Please report this at http://developer.pidgin.im\n",
762 status_file, strerror(errno)); 762 status_file, g_strerror(errno));
763 g_free(status_file); 763 g_free(status_file);
764 return FALSE; 764 return FALSE;
765 } 765 }
766 766
767 old_icons_dir = g_build_filename(old_user_dir, "icons", NULL); 767 old_icons_dir = g_build_filename(old_user_dir, "icons", NULL);