From 15fc2914e6ff6ce11920b07bc7155ed50268cb06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Mula=C4=8D?= Date: Thu, 31 Aug 2006 09:20:24 +0000 Subject: [PATCH] remove files which are long time undeliverable to undeliverable folder and forget about them - needs testing --- org.glite.lb.common/interface/lb_maildir.h | 2 +- org.glite.lb.common/src/lb_maildir.c | 60 ++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/org.glite.lb.common/interface/lb_maildir.h b/org.glite.lb.common/interface/lb_maildir.h index 45b2da8..50eb8d4 100644 --- a/org.glite.lb.common/interface/lb_maildir.h +++ b/org.glite.lb.common/interface/lb_maildir.h @@ -17,7 +17,7 @@ extern char lbm_errdesc[]; extern int edg_wll_MaildirInit(const char *); extern int edg_wll_MaildirStoreMsg(const char *, const char *, const char *); -extern int edg_wll_MaildirRetryTransStart(const char *, time_t, char **, char **); +extern int edg_wll_MaildirRetryTransStart(const char *, time_t, time_t, char **, char **); extern int edg_wll_MaildirTransStart(const char *, char **, char **); extern int edg_wll_MaildirTransEnd(const char *, char *, int); diff --git a/org.glite.lb.common/src/lb_maildir.c b/org.glite.lb.common/src/lb_maildir.c index 43df55e..c6024a3 100644 --- a/org.glite.lb.common/src/lb_maildir.c +++ b/org.glite.lb.common/src/lb_maildir.c @@ -16,10 +16,11 @@ enum { LBMD_DIR_TMP = 0, LBMD_DIR_NEW, LBMD_DIR_WORK, - LBMD_DIR_POST + LBMD_DIR_POST, + LBMD_DIR_UNDELIVERABLE }; -static const char *dirs[] = { "tmp", "new", "work", "post" }; +static const char *dirs[] = { "tmp", "new", "work", "post", "undeliverable" }; #define MAX_ERR_LEN 1024 @@ -169,21 +170,22 @@ int edg_wll_MaildirTransEnd( int edg_wll_MaildirRetryTransStart( - const char *root, - time_t tm, - char **msg, - char **fname) + const char *root, + time_t retry, + time_t remove, + char **msg, + char **fname) { - static DIR *dir = NULL; - struct dirent *ent; - time_t tlimit; - struct stat st; - char newfname[PATH_MAX], - oldfname[PATH_MAX], - *buf = NULL; - int fhnd, - toread, ct, - bufsz, bufuse; + static DIR *dir = NULL; + struct dirent *ent; + time_t tlimit_retry, tlimit_remove; + struct stat st; + char newfname[PATH_MAX], + oldfname[PATH_MAX], + *buf = NULL; + int fhnd, + toread, ct, + bufsz, bufuse; if ( !root ) root = DEFAULT_ROOT; @@ -197,7 +199,8 @@ int edg_wll_MaildirRetryTransStart( } } - tlimit = time(NULL) - tm; + tlimit_retry = time(NULL) - retry; + tlimit_remove = time(NULL) - remove; do { errno = 0; if ( !(ent = readdir(dir)) ) { @@ -221,7 +224,15 @@ int edg_wll_MaildirRetryTransStart( goto err; } - if ( st.st_ctime > tlimit ) continue; + /* if we cannot deliver the file for 'remove' time limit, */ + /* it is moved to undeliverable folder and forgotten */ + if ( st.st_mtime < tlimit_remove ) { + snprintf(newfname, PATH_MAX, "%s/%s/%s", + root, dirs[LBMD_DIR_UNDELIVERABLE], ent->d_name); + } + /* try to deliver file every 'retry' seconds */ + else if ( st.st_ctime > tlimit_retry ) continue; + if ( rename(oldfname, newfname) ) { if ( errno == ENOENT ) { @@ -232,8 +243,17 @@ int edg_wll_MaildirRetryTransStart( goto err; } } else { - /* we have found and moved the file with which we will work now */ - break; + if (st.st_mtime < tlimit_remove) { + /* we have moved undeliverable file to undeliverable folder */ + /* no other action needed */ + snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_TMP], ent->d_name); + unlink(oldfname); + continue; + } else { + /* we have found and moved the file to work folder */ + /* going to process it */ + break; + } } } while ( 1 ); -- 1.8.2.3