dovecot-1.1: Replaced HAVE_ST_NSEC macro checks with more generi...
dovecot at dovecot.org
dovecot at dovecot.org
Sat May 17 01:00:27 EEST 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/a957567706ec
changeset: 7526:a957567706ec
user: Timo Sirainen <tss at iki.fi>
date: Sat May 17 01:00:22 2008 +0300
description:
Replaced HAVE_ST_NSEC macro checks with more generic ST_?TIME_NSEC() macros
for getting the nanosecond and ST_NTIMES_EQUAL() macro for comparing them.
Added support for BSD st_?timespec fields.
diffstat:
4 files changed, 54 insertions(+), 37 deletions(-)
configure.in | 21 +++++++++++-
src/lib-storage/index/maildir/maildir-sync.c | 21 +-----------
src/lib-storage/index/maildir/maildir-uidlist.c | 11 +-----
src/lib/compat.h | 38 +++++++++++++++++------
diffs (164 lines):
diff -r 4c70d5f54409 -r a957567706ec configure.in
--- a/configure.in Sat May 17 00:40:31 2008 +0300
+++ b/configure.in Sat May 17 01:00:22 2008 +0300
@@ -1218,7 +1218,7 @@ AC_TRY_COMPILE([
AC_MSG_RESULT(no)
])
-AC_MSG_CHECKING([if struct stat has tv_nsec fields])
+AC_MSG_CHECKING([if struct stat has st_?tim timespec fields])
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/stat.h>
@@ -1229,7 +1229,24 @@ AC_TRY_COMPILE([
return 0;
], [
- AC_DEFINE(HAVE_STAT_TV_NSEC,, Define if you have tv_nsec fields in struct stat)
+ AC_DEFINE(HAVE_STAT_XTIM,, Define if you have st_?tim timespec fields in struct stat)
+ AC_MSG_RESULT(yes)
+], [
+ AC_MSG_RESULT(no)
+])
+
+AC_MSG_CHECKING([if struct stat has st_?timespec fields])
+AC_TRY_COMPILE([
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+], [
+ struct stat st;
+ unsigned long x = st.st_mtimespec.tv_nsec;
+
+ return 0;
+], [
+ AC_DEFINE(HAVE_STAT_XTIMESPEC,, Define if you have st_?timespec fields in struct stat)
AC_MSG_RESULT(yes)
], [
AC_MSG_RESULT(no)
diff -r 4c70d5f54409 -r a957567706ec src/lib-storage/index/maildir/maildir-sync.c
--- a/src/lib-storage/index/maildir/maildir-sync.c Sat May 17 00:40:31 2008 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c Sat May 17 01:00:22 2008 +0300
@@ -403,19 +403,11 @@ static int maildir_scan_dir(struct maild
if (new_dir) {
ctx->mbox->maildir_hdr.new_check_time = now;
ctx->mbox->maildir_hdr.new_mtime = st.st_mtime;
-#ifdef HAVE_STAT_TV_NSEC
- ctx->mbox->maildir_hdr.new_mtime_nsecs = st.st_mtim.tv_nsec;
-#else
- ctx->mbox->maildir_hdr.new_mtime_nsecs = 0;
-#endif
+ ctx->mbox->maildir_hdr.new_mtime_nsecs = ST_MTIME_NSEC(st);
} else {
ctx->mbox->maildir_hdr.cur_check_time = now;
ctx->mbox->maildir_hdr.cur_mtime = st.st_mtime;
-#ifdef HAVE_STAT_TV_NSEC
- ctx->mbox->maildir_hdr.cur_mtime_nsecs = st.st_mtim.tv_nsec;
-#else
- ctx->mbox->maildir_hdr.cur_mtime_nsecs = 0;
-#endif
+ ctx->mbox->maildir_hdr.cur_mtime_nsecs = ST_MTIME_NSEC(st);
}
src = t_str_new(1024);
@@ -538,13 +530,6 @@ static int maildir_sync_quick_check(stru
const char *new_dir, const char *cur_dir,
bool *new_changed_r, bool *cur_changed_r)
{
-#ifdef HAVE_STAT_TV_NSEC
-# define DIR_NSECS_CHANGED(st, hdr, name) \
- ((unsigned int)(st).st_mtim.tv_nsec != (hdr)->name ## _mtime_nsecs)
-#else
-# define DIR_NSECS_CHANGED(st, hdr, name) 0
-#endif
-
#define DIR_DELAYED_REFRESH(hdr, name) \
((hdr)->name ## _check_time <= \
(hdr)->name ## _mtime + MAILDIR_SYNC_SECS && \
@@ -553,7 +538,7 @@ static int maildir_sync_quick_check(stru
#define DIR_MTIME_CHANGED(st, hdr, name) \
((st).st_mtime != (time_t)(hdr)->name ## _mtime || \
- DIR_NSECS_CHANGED(st, hdr, name))
+ !ST_NTIMES_EQUAL(ST_MTIME_NSEC(st), (hdr)->name ## _mtime_nsecs))
struct maildir_index_header *hdr = &mbox->maildir_hdr;
struct stat new_st, cur_st;
diff -r 4c70d5f54409 -r a957567706ec src/lib-storage/index/maildir/maildir-uidlist.c
--- a/src/lib-storage/index/maildir/maildir-uidlist.c Sat May 17 00:40:31 2008 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c Sat May 17 01:00:22 2008 +0300
@@ -318,9 +318,7 @@ static void maildir_uidlist_update_hdr(s
struct maildir_index_header *mhdr = &uidlist->mbox->maildir_hdr;
mhdr->uidlist_mtime = st->st_mtime;
-#ifdef HAVE_STAT_TV_NSEC
- mhdr->uidlist_mtime_nsecs = st->st_mtim.tv_nsec;
-#endif
+ mhdr->uidlist_mtime_nsecs = ST_MTIME_NSEC(st);
mhdr->uidlist_size = st->st_size;
}
@@ -767,11 +765,8 @@ int maildir_uidlist_refresh_fast_init(st
return ret;
if (st.st_size == mhdr->uidlist_size &&
- st.st_mtime == mhdr->uidlist_mtime
-#ifdef HAVE_STAT_TV_NSEC
- && st.st_mtim.tv_nsec == mhdr->uidlist_mtime_nsecs
-#endif
- ) {
+ st.st_mtime == mhdr->uidlist_mtime &&
+ ST_NTIMES_EQUAL(ST_MTIME_NSEC(st), mhdr->uidlist_mtime_nsecs)) {
/* index is up-to-date */
hdr = mail_index_get_header(uidlist->mbox->ibox.view);
uidlist->uid_validity = hdr->uid_validity;
diff -r 4c70d5f54409 -r a957567706ec src/lib/compat.h
--- a/src/lib/compat.h Sat May 17 00:40:31 2008 +0300
+++ b/src/lib/compat.h Sat May 17 01:00:22 2008 +0300
@@ -63,17 +63,37 @@ typedef int socklen_t;
# error I do not know how to compare dev_t
#endif
-#ifdef HAVE_STAT_TV_NSEC
-# define CMP_ST_MTIME(st1, st2) \
+#ifdef HAVE_STAT_XTIM
+# define HAVE_ST_NSECS
+# define ST_ATIME_NSEC(st) ((unsigned long)(st).st_atim.tv_nsec)
+# define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtim.tv_nsec)
+# define ST_CTIME_NSEC(st) ((unsigned long)(st).st_ctim.tv_nsec)
+#elif defined (HAVE_STAT_XTIMESPEC)
+# define HAVE_ST_NSECS
+# define ST_ATIME_NSEC(st) ((unsigned long)(st).st_atimespec.tv_nsec)
+# define ST_MTIME_NSEC(st) ((unsigned long)(st).st_mtimespec.tv_nsec)
+# define ST_CTIME_NSEC(st) ((unsigned long)(st).st_ctimespec.tv_nsec)
+#else
+# define ST_ATIME_NSEC(st) 0UL
+# define ST_MTIME_NSEC(st) 0UL
+# define ST_CTIME_NSEC(st) 0UL
+#endif
+
+#ifdef HAVE_ST_NSECS
+/* TRUE if a nanosecond timestamp from struct stat matches another nanosecond.
+ If nanoseconds aren't supported in struct stat, returns always TRUE (useful
+ with NFS if some hosts support nanoseconds and others don't). */
+# define ST_NTIMES_EQUAL(ns1, ns2) ((ns1) == (ns2))
+#else
+# define ST_NTIMES_EQUAL(ns1, ns2) TRUE
+#endif
+
+#define CMP_ST_MTIME(st1, st2) \
((st1)->st_mtime == (st2)->st_mtime && \
- (st1)->st_mtim.tv_nsec == (st2)->st_mtim.tv_nsec)
-# define CMP_ST_CTIME(st1, st2) \
+ ST_NTIMES_EQUAL((st1)->st_mtim.tv_nsec, (st2)->st_mtim.tv_nsec))
+#define CMP_ST_CTIME(st1, st2) \
((st1)->st_ctime == (st2)->st_ctime && \
- (st1)->st_ctim.tv_nsec == (st2)->st_ctim.tv_nsec)
-#else
-# define CMP_ST_MTIME(st1, st2) ((st1)->st_mtime == (st2)->st_mtime)
-# define CMP_ST_CTIME(st1, st2) ((st1)->st_ctime == (st2)->st_ctime)
-#endif
+ ST_NTIMES_EQUAL((st1)->st_ctim.tv_nsec, (st2)->st_ctim.tv_nsec))
/* strcasecmp(), strncasecmp() */
#ifndef HAVE_STRCASECMP
More information about the dovecot-cvs
mailing list