]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dbox fixes
authorTimo Sirainen <tss@iki.fi>
Tue, 10 Mar 2009 01:10:44 +0000 (21:10 -0400)
committerTimo Sirainen <tss@iki.fi>
Tue, 10 Mar 2009 01:10:44 +0000 (21:10 -0400)
--HG--
branch : HEAD

src/lib-storage/index/dbox/dbox-map.c
src/lib-storage/index/dbox/dbox-sync-file.c

index cb812401ccc8986448b18537471a4f1fe33e84cd..bfd9c1de4a42a7cd80ab9606a7eab88e49080750 100644 (file)
@@ -574,7 +574,8 @@ dbox_map_find_appendable_file(struct dbox_map_append_context *ctx,
                if (*file_r != NULL)
                        return 1;
                /* FIXME: use retry_later somehow */
-               if (!mail_index_lookup_seq_range(map->view, 1, uid-1,
+               if (uid == 1 ||
+                   !mail_index_lookup_seq_range(map->view, 1, uid-1,
                                                 &seq1, &seq))
                        break;
                seq++;
index fd1248beea8538a4ea1156f03c43b5860be487d9..c7166c4ea229f8962ae7e6462ebb0df41ddc0ce9 100644 (file)
@@ -45,6 +45,7 @@ static int dbox_sync_file_unlink(struct dbox_file *file)
 int dbox_sync_file_cleanup(struct dbox_file *file)
 {
        struct dbox_file *out_file;
+       struct stat st;
        struct istream *input;
        struct ostream *output = NULL;
        struct dbox_metadata_header meta_hdr;
@@ -63,6 +64,18 @@ int dbox_sync_file_cleanup(struct dbox_file *file)
        if ((ret = dbox_file_try_lock(file)) <= 0)
                return ret;
 
+       /* make sure the file still exists. another process may have already
+          deleted it. */
+       if (stat(file->current_path, &st) < 0) {
+               dbox_file_unlock(file);
+               if (errno == ENOENT)
+                       return 0;
+
+               mail_storage_set_critical(&file->storage->storage,
+                       "stat(%s) failed: %m", file->current_path);
+               return -1;
+       }
+
        append_ctx = dbox_map_append_begin_storage(file->storage);
 
        i_array_init(&msgs_arr, 128);
@@ -153,8 +166,8 @@ int dbox_sync_file_cleanup(struct dbox_file *file)
                ret = -1;
        } else if (output == NULL) {
                /* everything expunged in this file, unlink it */
-               dbox_map_append_rollback(&append_ctx);
                ret = dbox_sync_file_unlink(file);
+               dbox_map_append_rollback(&append_ctx);
        } else {
                /* assign new file_id + offset to moved messages */
                if (dbox_map_append_move(append_ctx, &copied_map_uids,
@@ -163,8 +176,8 @@ int dbox_sync_file_cleanup(struct dbox_file *file)
                        dbox_map_append_rollback(&append_ctx);
                        ret = -1;
                } else {
-                       dbox_map_append_commit(&append_ctx);
                        (void)dbox_sync_file_unlink(file);
+                       dbox_map_append_commit(&append_ctx);
                        ret = 1;
                }
        }