commit 4da89af7be2d53e9a01981292edb289742b7be21
Author: Oswald Buddenhagen <[email protected]>
Date:   Thu Jan 1 19:18:27 2015 +0100

    refactor maildir_set_uid() and maildir_store_uidval()
    
    the latter now handles both the db and the plaintext file, so the former
    can make use of it.

 src/drv_maildir.c |   85 +++++++++++++++++++++++++--------------------
 1 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/src/drv_maildir.c b/src/drv_maildir.c
index 92d13f8..117e623 100644
--- a/src/drv_maildir.c
+++ b/src/drv_maildir.c
@@ -451,51 +451,42 @@ make_key( const char *info_stop, DBT *tkey, char *name )
        tkey->data = name;
        tkey->size = u ? (size_t)(u - name) : strlen( name );
 }
-
-static int
-maildir_set_uid( maildir_store_t *ctx, const char *name, int *uid )
-{
-       int ret, uv[2];
-
-       if (uid)
-               *uid = ++ctx->nuid;
-       key.data = (void *)"UIDVALIDITY";
-       key.size = 11;
-       uv[0] = ctx->gen.uidvalidity;
-       uv[1] = ctx->nuid;
-       value.data = uv;
-       value.size = sizeof(uv);
-       if ((ret = ctx->db->put( ctx->db, 0, &key, &value, 0 ))) {
-         tbork:
-               ctx->db->err( ctx->db, ret, "Maildir error: db->put()" );
-               return DRV_BOX_BAD;
-       }
-       if (uid) {
-               make_key( ((maildir_store_conf_t *)ctx->gen.conf)->info_stop, 
&key, (char *)name );
-               value.data = uid;
-               value.size = sizeof(*uid);
-               if ((ret = ctx->db->put( ctx->db, 0, &key, &value, 0 )))
-                       goto tbork;
-       }
-       if ((ret = ctx->db->sync( ctx->db, 0 ))) {
-               ctx->db->err( ctx->db, ret, "Maildir error: db->sync()" );
-               return DRV_BOX_BAD;
-       }
-       return DRV_OK;
-}
 #endif /* USE_DB */
 
 static int
 maildir_store_uidval( maildir_store_t *ctx )
 {
        int n;
+#ifdef USE_DB
+       int ret, uv[2];
+#endif
        char buf[128];
 
-       n = sprintf( buf, "%d\n%d\n", ctx->gen.uidvalidity, ctx->nuid );
-       lseek( ctx->uvfd, 0, SEEK_SET );
-       if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n ) || 
(UseFSync && fdatasync( ctx->uvfd ))) {
-               error( "Maildir error: cannot write UIDVALIDITY.\n" );
-               return DRV_BOX_BAD;
+#ifdef USE_DB
+       if (ctx->db) {
+               key.data = (void *)"UIDVALIDITY";
+               key.size = 11;
+               uv[0] = ctx->gen.uidvalidity;
+               uv[1] = ctx->nuid;
+               value.data = uv;
+               value.size = sizeof(uv);
+               if ((ret = ctx->db->put( ctx->db, 0, &key, &value, 0 ))) {
+                       ctx->db->err( ctx->db, ret, "Maildir error: db->put()" 
);
+                       return DRV_BOX_BAD;
+               }
+               if ((ret = ctx->db->sync( ctx->db, 0 ))) {
+                       ctx->db->err( ctx->db, ret, "Maildir error: db->sync()" 
);
+                       return DRV_BOX_BAD;
+               }
+       } else
+#endif /* USE_DB */
+       {
+               n = sprintf( buf, "%d\n%d\n", ctx->gen.uidvalidity, ctx->nuid );
+               lseek( ctx->uvfd, 0, SEEK_SET );
+               if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n 
) || (UseFSync && fdatasync( ctx->uvfd ))) {
+                       error( "Maildir error: cannot write UIDVALIDITY.\n" );
+                       return DRV_BOX_BAD;
+               }
        }
        conf_wakeup( &ctx->lcktmr, 2 );
        return DRV_OK;
@@ -511,7 +502,6 @@ maildir_init_uidval( maildir_store_t *ctx )
        if (ctx->db) {
                u_int32_t count;
                ctx->db->truncate( ctx->db, 0, &count, 0 );
-               return maildir_set_uid( ctx, 0, 0 );
        }
 #endif /* USE_DB */
        return maildir_store_uidval( ctx );
@@ -598,6 +588,25 @@ maildir_obtain_uid( maildir_store_t *ctx, int *uid )
        return maildir_store_uidval( ctx );
 }
 
+#ifdef USE_DB
+static int
+maildir_set_uid( maildir_store_t *ctx, const char *name, int *uid )
+{
+       int ret;
+
+       *uid = ++ctx->nuid;
+
+       make_key( ((maildir_store_conf_t *)ctx->gen.conf)->info_stop, &key, 
(char *)name );
+       value.data = uid;
+       value.size = sizeof(*uid);
+       if ((ret = ctx->db->put( ctx->db, 0, &key, &value, 0 ))) {
+               ctx->db->err( ctx->db, ret, "Maildir error: db->put()" );
+               return DRV_BOX_BAD;
+       }
+       return maildir_store_uidval( ctx );
+}
+#endif
+
 static int
 maildir_compare( const void *l, const void *r )
 {

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to