Mercurial > dovecot > original-hg > dovecot-1.2
changeset 7526:a957567706ec HEAD
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.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 17 May 2008 01:00:22 +0300 |
parents | 4c70d5f54409 |
children | 20c6e9545d56 |
files | configure.in src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/maildir/maildir-uidlist.c src/lib/compat.h |
diffstat | 4 files changed, 54 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- 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_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 @@ 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)
--- 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 @@ 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 @@ 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 @@ #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;
--- 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 @@ 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 @@ 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;
--- 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 @@ # 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