changeset 2078:b3daf55df932 HEAD

Added maildir_stat_dirs option.
author Timo Sirainen <tss@iki.fi>
date Sun, 30 May 2004 01:21:39 +0300
parents d5b20d679b8a
children 729431cc32c1
files configure.in dovecot-example.conf src/lib-storage/index/maildir/maildir-list.c src/master/mail-process.c src/master/master-settings.c src/master/master-settings.h
diffstat 6 files changed, 42 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Sun May 30 00:40:30 2004 +0300
+++ b/configure.in	Sun May 30 01:21:39 2004 +0300
@@ -448,6 +448,16 @@
     ;;
 esac
 
+dnl * Do we have struct dirent->d_type
+AC_TRY_COMPILE([
+  #include <dirent.h>
+], [
+  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 <limits.h>
--- a/dovecot-example.conf	Sun May 30 00:40:30 2004 +0300
+++ b/dovecot-example.conf	Sun May 30 01:21:39 2004 +0300
@@ -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
--- a/src/lib-storage/index/maildir/maildir-list.c	Sun May 30 00:40:30 2004 +0300
+++ b/src/lib-storage/index/maildir/maildir-list.c	Sun May 30 01:21:39 2004 +0300
@@ -10,6 +10,7 @@
 #include "maildir-storage.h"
 #include "mailbox-tree.h"
 
+#include <stdlib.h>
 #include <dirent.h>
 #include <sys/stat.h>
 
@@ -53,11 +54,12 @@
 {
 	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 @@
 		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 @@
 		    (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 @@
 			   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 &&
--- a/src/master/mail-process.c	Sun May 30 00:40:30 2004 +0300
+++ b/src/master/mail-process.c	Sun May 30 01:21:39 2004 +0300
@@ -314,6 +314,8 @@
 		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)
--- a/src/master/master-settings.c	Sun May 30 00:40:30 2004 +0300
+++ b/src/master/master-settings.c	Sun May 30 01:21:39 2004 +0300
@@ -93,6 +93,7 @@
 	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 @@
 	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",
--- a/src/master/master-settings.h	Sun May 30 00:40:30 2004 +0300
+++ b/src/master/master-settings.h	Sun May 30 01:21:39 2004 +0300
@@ -68,6 +68,7 @@
 	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;