From: Paul Mangan Date: Sat, 27 Jul 2002 09:58:16 +0000 (+0000) Subject: sync with 0.8.1cvs2 X-Git-Tag: rel_0_8_1~9 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=39a51c549ac742335efd2be8ef419dcd2a045813 sync with 0.8.1cvs2 --- diff --git a/ChangeLog b/ChangeLog index 2c41a71e2..e98a52a7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-07-26 + + * src/news.c: implement automatic cache expiration. + news_delete_expired_caches(): new. + news_get_article_list(): fixed a bug that nonexistent messages + were not removed from list. + * src/procmsg.[ch]: procmsg_get_last_num_in_msg_list(): renamed + procmsg_get_last_num_in_cache(). + * src/utils.[ch]: remove_expired_files(): new. + 2002-07-26 * src/inc.c: diff --git a/ChangeLog.claws b/ChangeLog.claws index b8fe61fae..3287b1db6 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2002-07-27 [paul] 0.8.0claws22 + + * sync with 0.8.1cvs2 + see ChangeLog 2002-07-26 + 2002-07-27 [christoph] 0.8.0claws21 * src/imap.c diff --git a/ChangeLog.jp b/ChangeLog.jp index 45a9739d1..a065463a9 100644 --- a/ChangeLog.jp +++ b/ChangeLog.jp @@ -1,3 +1,13 @@ +2002-07-26 + + * src/news.c: ¼«Æ°¥­¥ã¥Ã¥·¥åºï½ü¤ò¼ÂÁõ¡£ + news_delete_expired_caches(): ¿·µ¬¡£ + news_get_article_list(): ¸ºß¤·¤Ê¤¤¥á¥Ã¥»¡¼¥¸¤¬¥ê¥¹¥È¤«¤éºï½ü + ¤µ¤ì¤Ê¤¤¥Ð¥°¤ò½¤Àµ¡£ + * src/procmsg.[ch]: procmsg_get_last_num_in_msg_list(): + procmsg_get_last_num_in_cache() ¤ò̾¾ÎÊѹ¹¡£ + * src/utils.[ch]: remove_expired_files(): ¿·µ¬¡£ + 2002-07-26 * src/inc.c diff --git a/configure.in b/configure.in index 58fdc32c3..512563131 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=8 MICRO_VERSION=0 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws21 +EXTRA_VERSION=claws22 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/imap.c b/src/imap.c index 834135f03..6973b26c1 100644 --- a/src/imap.c +++ b/src/imap.c @@ -563,7 +563,7 @@ GSList *imap_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache) if (!session) { mlist = procmsg_read_cache(item, FALSE); - item->last_num = procmsg_get_last_num_in_cache(mlist); + item->last_num = procmsg_get_last_num_in_msg_list(mlist); procmsg_set_flags(mlist, item); statusbar_pop_all(); return mlist; @@ -591,7 +591,7 @@ GSList *imap_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache) mlist = procmsg_read_cache(item, FALSE); procmsg_set_flags(mlist, item); - cache_last = procmsg_get_last_num_in_cache(mlist); + cache_last = procmsg_get_last_num_in_msg_list(mlist); /* calculating the range of envelope to get */ if (item->mtime != uid_validity) { diff --git a/src/news.c b/src/news.c index 56c8a036e..095c12fb9 100644 --- a/src/news.c +++ b/src/news.c @@ -98,6 +98,8 @@ static GSList *news_delete_old_articles (GSList *alist, FolderItem *item, gint first); static void news_delete_all_articles (FolderItem *item); +static void news_delete_expired_caches (GSList *alist, + FolderItem *item); static gint news_remove_msg (Folder *folder, FolderItem *item, @@ -289,7 +291,7 @@ GSList *news_get_article_list(Folder *folder, FolderItem *item, if (!session) { alist = procmsg_read_cache(item, FALSE); - item->last_num = procmsg_get_last_num_in_cache(alist); + item->last_num = procmsg_get_last_num_in_msg_list(alist); } else if (use_cache) { GSList *newlist; gint cache_last; @@ -297,12 +299,20 @@ GSList *news_get_article_list(Folder *folder, FolderItem *item, alist = procmsg_read_cache(item, FALSE); - cache_last = procmsg_get_last_num_in_cache(alist); + cache_last = procmsg_get_last_num_in_msg_list(alist); newlist = news_get_uncached_articles (session, item, cache_last, &first, &last); - alist = news_delete_old_articles(alist, item, first); + if (first == 0 && last == 0) { + news_delete_all_articles(item); + procmsg_msg_list_free(alist); + alist = NULL; + } else { + alist = news_delete_old_articles(alist, item, first); + news_delete_expired_caches(alist, item); + } alist = g_slist_concat(alist, newlist); + item->last_num = last; } else { gint last; @@ -692,8 +702,8 @@ static GSList *news_get_uncached_articles(NNTPSession *session, GSList *llast = NULL; MsgInfo *msginfo; - if (rfirst) *rfirst = 0; - if (rlast) *rlast = 0; + if (rfirst) *rfirst = -1; + if (rlast) *rlast = -1; g_return_val_if_fail(session != NULL, NULL); g_return_val_if_fail(item != NULL, NULL); @@ -712,6 +722,10 @@ static GSList *news_get_uncached_articles(NNTPSession *session, first, last); return NULL; } + + if (rfirst) *rfirst = first; + if (rlast) *rlast = last; + if (cache_last < first) begin = first; else if (last < cache_last) @@ -723,9 +737,6 @@ static GSList *news_get_uncached_articles(NNTPSession *session, begin = cache_last + 1; end = last; - if (rfirst) *rfirst = first; - if (rlast) *rlast = last; - if (prefs_common.max_articles > 0 && end - begin + 1 > prefs_common.max_articles) begin = end - prefs_common.max_articles + 1; @@ -930,7 +941,7 @@ static GSList *news_delete_old_articles(GSList *alist, FolderItem *item, if (first < 2) return alist; - debug_print(_("Deleting cached articles 1 - %d ... "), first - 1); + debug_print("Deleting cached articles 1 - %d ...\n", first - 1); dir = folder_item_get_path(item); remove_numbered_files(dir, 1, first - 1); @@ -947,7 +958,6 @@ static GSList *news_delete_old_articles(GSList *alist, FolderItem *item, cur = next; } - debug_print(_("done.\n")); return alist; } @@ -960,13 +970,26 @@ static void news_delete_all_articles(FolderItem *item) g_return_if_fail(item->folder != NULL); g_return_if_fail(item->folder->type == F_NEWS); - debug_print(_("\tDeleting all cached articles... ")); + debug_print("Deleting all cached articles...\n"); dir = folder_item_get_path(item); remove_all_numbered_files(dir); g_free(dir); +} - debug_print(_("done.\n")); +static void news_delete_expired_caches(GSList *alist, FolderItem *item) +{ + gchar *dir; + + g_return_if_fail(item != NULL); + g_return_if_fail(item->folder != NULL); + g_return_if_fail(item->folder->type == F_NEWS); + + debug_print("Deleting expired cached articles...\n"); + + dir = folder_item_get_path(item); + remove_expired_files(dir, 24 * 7); + g_free(dir); } gint news_cancel_article(Folder * folder, MsgInfo * msginfo) diff --git a/src/procmsg.c b/src/procmsg.c index 00d8e0571..64a501e88 100644 --- a/src/procmsg.c +++ b/src/procmsg.c @@ -334,14 +334,12 @@ void procmsg_set_flags(GSList *mlist, FolderItem *item) g_hash_table_destroy(mark_table); } -gint procmsg_get_last_num_in_cache(GSList *mlist) +gint procmsg_get_last_num_in_msg_list(GSList *mlist) { GSList *cur; MsgInfo *msginfo; gint last = 0; - if (mlist == NULL) return 0; - for (cur = mlist; cur != NULL; cur = cur->next) { msginfo = (MsgInfo *)cur->data; if (msginfo && msginfo->msgnum > last) diff --git a/src/procmsg.h b/src/procmsg.h index a7d8b2bf9..da945239e 100644 --- a/src/procmsg.h +++ b/src/procmsg.h @@ -218,7 +218,7 @@ GSList *procmsg_read_cache (FolderItem *item, gboolean scan_file); void procmsg_set_flags (GSList *mlist, FolderItem *item); -gint procmsg_get_last_num_in_cache (GSList *mlist); +gint procmsg_get_last_num_in_msg_list(GSList *mlist); void procmsg_msg_list_free (GSList *mlist); void procmsg_write_cache (MsgInfo *msginfo, FILE *fp); diff --git a/src/utils.c b/src/utils.c index 4d33b92bd..498faa80c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1752,6 +1752,60 @@ gint remove_all_numbered_files(const gchar *dir) return remove_numbered_files(dir, 0, UINT_MAX); } +gint remove_expired_files(const gchar *dir, guint hours) +{ + DIR *dp; + struct dirent *d; + struct stat s; + gchar *prev_dir; + gint fileno; + time_t mtime, now, expire_time; + + prev_dir = g_get_current_dir(); + + if (chdir(dir) < 0) { + FILE_OP_ERROR(dir, "chdir"); + return -1; + } + + if ((dp = opendir(".")) == NULL) { + FILE_OP_ERROR(dir, "opendir"); + return -1; + } + + now = time(NULL); + expire_time = hours * 60 * 60; + + while ((d = readdir(dp)) != NULL) { + fileno = to_number(d->d_name); + if (fileno >= 0) { + if (stat(d->d_name, &s) < 0) { + FILE_OP_ERROR(d->d_name, "stat"); + continue; + } + if (S_ISDIR(s.st_mode)) + continue; + mtime = MAX(s.st_mtime, s.st_atime); + if (now - mtime > expire_time) { + if (unlink(d->d_name) < 0) + FILE_OP_ERROR(d->d_name, "unlink"); + } + } + } + + closedir(dp); + + if (chdir(prev_dir) < 0) { + FILE_OP_ERROR(prev_dir, "chdir"); + g_free(prev_dir); + return -1; + } + + g_free(prev_dir); + + return 0; +} + gint remove_dir_recursive(const gchar *dir) { struct stat s; diff --git a/src/utils.h b/src/utils.h index bc4e79615..b99fd964f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -326,6 +326,8 @@ gint remove_numbered_files (const gchar *dir, guint first, guint last); gint remove_all_numbered_files (const gchar *dir); +gint remove_expired_files (const gchar *dir, + guint hours); gint remove_dir_recursive (const gchar *dir); gint copy_file (const gchar *src, const gchar *dest);