From: Timo Sirainen Date: Sat, 29 May 2004 22:21:39 +0000 (+0300) Subject: Added maildir_stat_dirs option. X-Git-Tag: 1.1.alpha1~4028 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7869168597ac562d7eadb86e8cbb9bd7c7b571a;p=thirdparty%2Fdovecot%2Fcore.git Added maildir_stat_dirs option. --HG-- branch : HEAD --- diff --git a/configure.in b/configure.in index 3d0ff5dacf..03400b450e 100644 --- a/configure.in +++ b/configure.in @@ -448,6 +448,16 @@ case "$typeof_off_t" in ;; esac +dnl * Do we have struct dirent->d_type +AC_TRY_COMPILE([ + #include +], [ + struct dirent d; + d.d_type = DT_DIR; +], [ + AC_DEFINE(HAVE_DIRENT_D_TYPE,, Define if you have struct dirent->d_type) +]) + dnl * Do we have OFF_T_MAX? AC_TRY_COMPILE([ #include diff --git a/dovecot-example.conf b/dovecot-example.conf index 11407c0121..f1e7921ad0 100644 --- a/dovecot-example.conf +++ b/dovecot-example.conf @@ -270,6 +270,13 @@ # which may be slower. Required for NFS. #fcntl_locks_disable = no +# By default LIST command returns all entries in maildir beginning with dot. +# Enabling this option makes Dovecot return only entries which are directories. +# This is done by stat()ing each entry, so it causes more disk I/O. +# (For systems setting struct dirent->d_type, this check is free and it's +# done always regardless of this setting) +#maildir_stat_dirs = no + # Copy mail to another folders using hard links. This is much faster than # actually copying the file. This is problematic only if something modifies # the mail in one folder but doesn't want it modified in the others. I don't diff --git a/src/lib-storage/index/maildir/maildir-list.c b/src/lib-storage/index/maildir/maildir-list.c index d554f6297b..313aeae0d8 100644 --- a/src/lib-storage/index/maildir/maildir-list.c +++ b/src/lib-storage/index/maildir/maildir-list.c @@ -10,6 +10,7 @@ #include "maildir-storage.h" #include "mailbox-tree.h" +#include #include #include @@ -53,11 +54,12 @@ static int maildir_fill_readdir(struct maildir_list_context *ctx, { DIR *dirp; struct dirent *d; + struct stat st; const char *path, *p, *mailbox_c; string_t *mailbox; enum imap_match_result match; struct mailbox_node *node; - int created; + int stat_dirs, created, hide; dirp = opendir(ctx->dir); if (dirp == NULL) { @@ -75,6 +77,8 @@ static int maildir_fill_readdir(struct maildir_list_context *ctx, node->flags &= ~(MAILBOX_PLACEHOLDER | MAILBOX_NONEXISTENT); } + stat_dirs = getenv("MAILDIR_STAT_DIRS") != NULL; + mailbox = t_str_new(PATH_MAX); while ((d = readdir(dirp)) != NULL) { const char *fname = d->d_name; @@ -87,10 +91,22 @@ static int maildir_fill_readdir(struct maildir_list_context *ctx, (fname[1] == '\0' || (fname[1] == '.' && fname[2] == '\0'))) continue; - /* FIXME: kludges. these files must be renamed later */ - if (strcmp(fname, ".customflags") == 0 || - strcmp(fname, ".subscriptions") == 0) +#ifdef HAVE_DIRENT_D_TYPE + /* check the type always since there's no extra cost */ + if (d->d_type == DT_DIR) + ; + else if (d->d_type != DT_UNKNOWN) continue; + else +#endif + if (stat_dirs) { + t_push(); + path = t_strdup_printf("%s/%s", ctx->dir, fname); + hide = stat(path, &st) < 0 || !S_ISDIR(st.st_mode); + t_pop(); + if (hide) + continue; + } if (fname[1] == MAILDIR_FS_SEP) { /* this mailbox is in the middle of being deleted, @@ -99,8 +115,6 @@ static int maildir_fill_readdir(struct maildir_list_context *ctx, delete it ourself if it's been there longer than one hour. don't touch it if it's outside our mail root dir. */ - struct stat st; - t_push(); path = t_strdup_printf("%s/%s", ctx->dir, fname); if (stat(path, &st) == 0 && diff --git a/src/master/mail-process.c b/src/master/mail-process.c index 20f85c72d3..cbf1ae5a05 100644 --- a/src/master/mail-process.c +++ b/src/master/mail-process.c @@ -314,6 +314,8 @@ int create_mail_process(struct login_group *group, int socket, env_put("MMAP_NO_WRITE=1"); if (set->fcntl_locks_disable) env_put("FCNTL_LOCKS_DISABLE=1"); + if (set->maildir_stat_dirs) + env_put("MAILDIR_STAT_DIRS=1"); if (set->maildir_copy_with_hardlinks) env_put("MAILDIR_COPY_WITH_HARDLINKS=1"); if (set->maildir_check_content_changes) diff --git a/src/master/master-settings.c b/src/master/master-settings.c index 2264639e07..1be9b89568 100644 --- a/src/master/master-settings.c +++ b/src/master/master-settings.c @@ -93,6 +93,7 @@ static struct setting_def setting_defs[] = { DEF(SET_BOOL, mmap_disable), DEF(SET_BOOL, mmap_no_write), DEF(SET_BOOL, fcntl_locks_disable), + DEF(SET_BOOL, maildir_stat_dirs), DEF(SET_BOOL, maildir_copy_with_hardlinks), DEF(SET_BOOL, maildir_check_content_changes), DEF(SET_STR, mbox_locks), @@ -226,6 +227,7 @@ struct settings default_settings = { MEMBER(mmap_no_write) FALSE, #endif MEMBER(fcntl_locks_disable) FALSE, + MEMBER(maildir_stat_dirs) FALSE, MEMBER(maildir_copy_with_hardlinks) FALSE, MEMBER(maildir_check_content_changes) FALSE, MEMBER(mbox_locks) "dotlock fcntl", diff --git a/src/master/master-settings.h b/src/master/master-settings.h index b82d3d8e1e..588bf486e2 100644 --- a/src/master/master-settings.h +++ b/src/master/master-settings.h @@ -68,6 +68,7 @@ struct settings { int mmap_disable; int mmap_no_write; int fcntl_locks_disable; + int maildir_stat_dirs; int maildir_copy_with_hardlinks; int maildir_check_content_changes; const char *mbox_locks;