From: Paul Mangan Date: Sun, 23 Nov 2003 05:03:32 +0000 (+0000) Subject: sync with 0.9.7cvs5 X-Git-Tag: rel_0_9_7~13 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=1e59d89dba69ad62f2e44524b24aaae1830786be sync with 0.9.7cvs5 --- diff --git a/ChangeLog b/ChangeLog index af29fc5d1..3077bf775 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2003-11-21 + + * configure.in: added check for d_type member in struct dirent. + * src/mh.c: mh_scan_folder(): use d->d_type if available. + mh_get_uncached_msgs(): removed redundant stat(). + mh_parse_msg(): return NULL if not a regular file. + mh_scan_tree_recursive(): use d->d_type if available. + * src/utils.[ch]: + dirent_is_regular_file() + dirent_is_directory(): new. Use d->d_type to determine the type + of entry if available. + remove_dir_recursive(): use dirent_is_directory(). + 2003-11-14 * src/folder.h: added 'updated' flag to FolderItem. diff --git a/ChangeLog.claws b/ChangeLog.claws index b17a370f3..25a642b89 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2003-11-22 [paul] 0.9.6claws88 + + * sync with 0.9.7cvs5 + see ChangeLog 2003-11-21 + 2003-11-21 [paul] 0.9.6claws87 * src/mimeview.c diff --git a/ChangeLog.jp b/ChangeLog.jp index 571f33e1d..09504b82f 100644 --- a/ChangeLog.jp +++ b/ChangeLog.jp @@ -1,3 +1,16 @@ +2003-11-21 + + * configure.in: struct dirent Ãæ¤Î d_type ¥á¥ó¥Ð¤Î¥Á¥§¥Ã¥¯¤òÄɲᣠ+ * src/mh.c: mh_scan_folder(): ÍøÍѲÄǽ¤Ê¾ì¹ç¤Ï d->d_type ¤ò»ÈÍÑ¡£ + mh_get_uncached_msgs(): ;ʬ¤Ê stat() ¤òºï½ü¡£ + mh_parse_msg(): Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤Ç¤Ê¤¤¾ì¹ç¤Ï NULL ¤òÊÖ¤¹¡£ + mh_scan_tree_recursive(): ÍøÍѲÄǽ¤Ê¾ì¹ç¤Ï d->d_type ¤ò»ÈÍÑ¡£ + * src/utils.[ch]: + dirent_is_regular_file() + dirent_is_directory(): ¿·µ¬¡£ÍøÍѲÄǽ¤Ê¾ì¹ç¤Ï¥¨¥ó¥È¥ê¤Î¥¿¥¤¥×¤ò + ȽÊ̤¹¤ë¤Î¤Ë d->d_type ¤ò»ÈÍÑ¡£ + remove_dir_recursive(): dirent_is_directory() ¤ò»ÈÍÑ¡£ + 2003-11-14 * src/folder.h: FolderItem ¤Ë 'updated' ¥Õ¥é¥°¤òÄɲᣠdiff --git a/configure.ac b/configure.ac index 571f7b4dd..ab988780e 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=9 MICRO_VERSION=6 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=87 +EXTRA_VERSION=88 if test $EXTRA_VERSION -eq 0; then VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws else @@ -132,6 +132,19 @@ else AC_MSG_RESULT(no) fi +dnl Check for d_type member in struct dirent +AC_MSG_CHECKING([whether struct dirent has d_type member]) +AC_CACHE_VAL(ac_cv_dirent_d_type,[ + AC_TRY_COMPILE([#include ], + [struct dirent d; d.d_type = DT_REG;], + ac_cv_dirent_d_type=yes, ac_cv_dirent_d_type=no) +]) +AC_MSG_RESULT($ac_cv_dirent_d_type) +if test $ac_cv_dirent_d_type = yes; then + AC_DEFINE(HAVE_DIRENT_D_TYPE, 1, + Define if `struct dirent' has `d_type' member.) +fi + dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC diff --git a/src/common/utils.c b/src/common/utils.c index d8a7d15ee..13901e8b8 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1767,6 +1767,34 @@ gboolean is_file_entry_exist(const gchar *file) return TRUE; } +gboolean dirent_is_regular_file(struct dirent *d) +{ + struct stat s; + +#ifdef HAVE_DIRENT_D_TYPE + if (d->d_type == DT_REG) + return TRUE; + else if (d->d_type != DT_UNKNOWN) + return FALSE; +#endif + + return (stat(d->d_name, &s) == 0 && S_ISREG(s.st_mode)); +} + +gboolean dirent_is_directory(struct dirent *d) +{ + struct stat s; + +#ifdef HAVE_DIRENT_D_TYPE + if (d->d_type == DT_DIR) + return TRUE; + else if (d->d_type != DT_UNKNOWN) + return FALSE; +#endif + + return (stat(d->d_name, &s) == 0 && S_ISDIR(s.st_mode)); +} + gint change_dir(const gchar *dir) { gchar *prevdir = NULL; @@ -2076,14 +2104,9 @@ gint remove_dir_recursive(const gchar *dir) !strcmp(d->d_name, "..")) continue; - if (stat(d->d_name, &s) < 0) { - FILE_OP_ERROR(d->d_name, "stat"); - continue; - } - /* g_print("removing %s\n", d->d_name); */ - if (S_ISDIR(s.st_mode)) { + if (dirent_is_directory(d)) { if (remove_dir_recursive(d->d_name) < 0) { g_warning("can't remove directory\n"); return -1; diff --git a/src/common/utils.h b/src/common/utils.h index 88c2f7ec5..6851f667c 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #if HAVE_ALLOCA_H # include @@ -334,6 +335,8 @@ gboolean file_exist (const gchar *file, gboolean allow_fifo); gboolean is_dir_exist (const gchar *dir); gboolean is_file_entry_exist (const gchar *file); +gboolean dirent_is_regular_file (struct dirent *d); +gboolean dirent_is_directory (struct dirent *d); #define is_file_exist(file) file_exist(file, FALSE) #define is_file_or_fifo_exist(file) file_exist(file, TRUE) diff --git a/src/mh.c b/src/mh.c index 7902f44c3..b107833f3 100644 --- a/src/mh.c +++ b/src/mh.c @@ -176,7 +176,6 @@ void mh_get_last_num(Folder *folder, FolderItem *item) gchar *path; DIR *dp; struct dirent *d; - struct stat s; gint max = 0; gint num; @@ -199,8 +198,7 @@ void mh_get_last_num(Folder *folder, FolderItem *item) while ((d = readdir(dp)) != NULL) { if ((num = to_number(d->d_name)) >= 0 && - stat(d->d_name, &s) == 0 && - S_ISREG(s.st_mode)) { + dirent_is_regular_file(d)) { if (max < num) max = num; } @@ -217,7 +215,6 @@ gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean * gchar *path; DIR *dp; struct dirent *d; - struct stat s; gint num, nummsgs = 0; g_return_val_if_fail(item != NULL, -1); @@ -240,11 +237,9 @@ gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean * } while ((d = readdir(dp)) != NULL) { - if ((num = to_number(d->d_name)) >= 0 && - stat(d->d_name, &s) == 0 && - S_ISREG(s.st_mode)) { + if ((num = to_number(d->d_name)) >= 0) { *list = g_slist_prepend(*list, GINT_TO_POINTER(num)); - nummsgs++; + nummsgs++; } } closedir(dp); @@ -705,32 +700,32 @@ static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item) MsgInfo *msginfo; MsgFlags flags; - flags.perm_flags = MSG_NEW|MSG_UNREAD; - flags.tmp_flags = 0; - g_return_val_if_fail(item != NULL, NULL); g_return_val_if_fail(file != NULL, NULL); + flags.perm_flags = MSG_NEW|MSG_UNREAD; + flags.tmp_flags = 0; + if (item->stype == F_QUEUE) { MSG_SET_TMP_FLAGS(flags, MSG_QUEUED); } else if (item->stype == F_DRAFT) { MSG_SET_TMP_FLAGS(flags, MSG_DRAFT); } + if (stat(file, &s) < 0) { + FILE_OP_ERROR(file, "stat"); + return NULL; + } + if (!S_ISREG(s.st_mode)) + return NULL; + msginfo = procheader_parse_file(file, flags, FALSE, FALSE); if (!msginfo) return NULL; msginfo->msgnum = atoi(file); msginfo->folder = item; - - if (stat(file, &s) < 0) { - FILE_OP_ERROR(file, "stat"); - msginfo->size = 0; - msginfo->mtime = 0; - } else { - msginfo->size = s.st_size; - msginfo->mtime = s.st_mtime; - } + msginfo->size = s.st_size; + msginfo->mtime = s.st_mtime; return msginfo; } @@ -828,13 +823,16 @@ static void mh_scan_tree_recursive(FolderItem *item) else entry = g_strdup(d->d_name); - if (stat(entry, &s) < 0) { - FILE_OP_ERROR(entry, "stat"); - g_free(entry); - continue; - } - - if (S_ISDIR(s.st_mode)) { + if ( +#ifdef HAVE_DIRENT_D_TYPE + d->d_type == DT_DIR || + (d->d_type == DT_UNKNOWN && +#endif + stat(entry, &s) == 0 && S_ISDIR(s.st_mode) +#ifdef HAVE_DIRENT_D_TYPE + ) +#endif + ) { FolderItem *new_item = NULL; GNode *node;