libpurple/log.c

branch
release-2.x.y
changeset 35995
d0bbb2dad7f3
parent 35992
34a67264df99
child 36002
31a8779e91d4
child 36027
175e769076e1
equal deleted inserted replaced
35994:4a39ea245fe6 35995:d0bbb2dad7f3
1702 log_last_modified = st.st_mtime; 1702 log_last_modified = st.st_mtime;
1703 1703
1704 /* Change the .log extension to .idx */ 1704 /* Change the .log extension to .idx */
1705 strcpy(pathstr + strlen(pathstr) - 3, "idx"); 1705 strcpy(pathstr + strlen(pathstr) - 3, "idx");
1706 1706
1707 if (g_stat(pathstr, &st) == 0) 1707 index_fd = g_open(pathstr, 0, O_RDONLY);
1708 { 1708 if (index_fd != -1) {
1709 if (fstat(index_fd, &st) != 0) {
1710 close(index_fd);
1711 index_fd = -1;
1712 }
1713 }
1714
1715 if (index_fd != -1) {
1709 if (st.st_mtime < log_last_modified) 1716 if (st.st_mtime < log_last_modified)
1710 { 1717 {
1711 purple_debug_warning("log", "Index \"%s\" exists, but is older than the log.\n", pathstr); 1718 purple_debug_warning("log", "Index \"%s\" exists, but is older than the log.\n", pathstr);
1712 } 1719 }
1713 else 1720 else
1714 { 1721 {
1715 /* The index file exists and is at least as new as the log, so open it. */ 1722 /* The index file exists and is at least as new as the log, so open it. */
1716 if (!(index = g_fopen(pathstr, "rb"))) 1723 if (!(index = fdopen(index_fd, "rb"))) {
1717 {
1718 purple_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n", 1724 purple_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n",
1719 pathstr, g_strerror(errno)); 1725 pathstr, g_strerror(errno));
1720 1726
1721 /* Fall through so that we'll parse the log file. */ 1727 /* Fall through so that we'll parse the log file. */
1722 } 1728 } else {
1723 else
1724 {
1725 purple_debug_info("log", "Using index: %s\n", pathstr); 1729 purple_debug_info("log", "Using index: %s\n", pathstr);
1726 g_free(pathstr); 1730 g_free(pathstr);
1727 while (fgets(buf, BUF_LONG, index)) 1731 while (fgets(buf, BUF_LONG, index))
1728 { 1732 {
1729 unsigned long idx_time; 1733 unsigned long idx_time;

mercurial