commit 5f4e3b285eb444b4bd01606d6ceb57f77ad282dd
parent 926788f3ae17f93edd5136979cd7d61e239c8dcc
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date: Mon, 29 Dec 2014 02:00:18 +0100
factor out maildir_clear_tmp()
Diffstat:
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/src/drv_maildir.c b/src/drv_maildir.c
@@ -336,12 +336,42 @@ maildir_free_scan( msglist_t *msglist )
#define _24_HOURS (3600 * 24)
static int
-maildir_validate( const char *box, int create, maildir_store_t *ctx )
+maildir_clear_tmp( char *buf, int bufsz, int bl )
{
DIR *dirp;
struct dirent *entry;
- char *p;
time_t now;
+ struct stat st;
+
+ memcpy( buf + bl, "tmp/", 5 );
+ bl += 4;
+ if (!(dirp = opendir( buf ))) {
+ sys_error( "Maildir error: cannot list %s", buf );
+ return DRV_BOX_BAD;
+ }
+ time( &now );
+ while ((entry = readdir( dirp ))) {
+ nfsnprintf( buf + bl, bufsz - bl, "%s", entry->d_name );
+ if (stat( buf, &st )) {
+ if (errno != ENOENT)
+ sys_error( "Maildir error: cannot access %s", buf );
+ } else if (S_ISREG(st.st_mode) && now - st.st_ctime >= _24_HOURS) {
+ /* This should happen infrequently enough that it won't be
+ * bothersome to the user to display when it occurs.
+ */
+ info( "Maildir notice: removing stale file %s\n", buf );
+ if (unlink( buf ) && errno != ENOENT)
+ sys_error( "Maildir error: cannot remove %s", buf );
+ }
+ }
+ closedir( dirp );
+ return DRV_OK;
+}
+
+static int
+maildir_validate( const char *box, int create, maildir_store_t *ctx )
+{
+ char *p;
int i, bl, ret;
struct stat st;
char buf[_POSIX_PATH_MAX];
@@ -386,28 +416,8 @@ maildir_validate( const char *box, int create, maildir_store_t *ctx )
return DRV_BOX_BAD;
}
}
- memcpy( buf + bl, "tmp/", 5 );
- bl += 4;
- if (!(dirp = opendir( buf ))) {
- sys_error( "Maildir error: cannot list %s", buf );
- return DRV_BOX_BAD;
- }
- time( &now );
- while ((entry = readdir( dirp ))) {
- nfsnprintf( buf + bl, sizeof(buf) - bl, "%s", entry->d_name );
- if (stat( buf, &st )) {
- if (errno != ENOENT)
- sys_error( "Maildir error: cannot access %s", buf );
- } else if (S_ISREG(st.st_mode) && now - st.st_ctime >= _24_HOURS) {
- /* this should happen infrequently enough that it won't be
- * bothersome to the user to display when it occurs.
- */
- info( "Maildir notice: removing stale file %s\n", buf );
- if (unlink( buf ) && errno != ENOENT)
- sys_error( "Maildir error: cannot remove %s", buf );
- }
- }
- closedir( dirp );
+ if ((ret = maildir_clear_tmp( buf, sizeof(buf), bl )) != DRV_OK)
+ return ret;
ctx->fresh = 0;
}
return DRV_OK;