]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Saving now closes newly created files if they become full.
authorTimo Sirainen <tss@iki.fi>
Tue, 9 Feb 2010 16:54:34 +0000 (18:54 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 9 Feb 2010 16:54:34 +0000 (18:54 +0200)
Newly created files also aren't locked anymore, they're not visible to
others anyway until map index is updated.

--HG--
branch : HEAD

src/lib-storage/index/dbox-common/dbox-file.c
src/lib-storage/index/dbox-multi/mdbox-file.c
src/lib-storage/index/dbox-multi/mdbox-map.c

index 18f3459209ba0aa89c6c71d47343f293ffe419ab..b4af99223247bb8519c271ca4e968c96ecab690e 100644 (file)
@@ -264,7 +264,7 @@ int dbox_file_try_lock(struct dbox_file *file)
 
 void dbox_file_unlock(struct dbox_file *file)
 {
-       i_assert(!file->appending);
+       i_assert(!file->appending || file->lock == NULL);
 
        if (file->lock != NULL)
                file_unlock(&file->lock);
index 067291101aac2ddd6470f9ca1c3dc4da5477f220..d897d5502409b1900b3585dca40a16739a8c97f7 100644 (file)
@@ -104,24 +104,11 @@ static void mdbox_file_init_paths(struct mdbox_file *file, const char *fname)
 static int mdbox_file_create(struct dbox_file *file)
 {
        bool create_parents;
-       int ret;
 
        create_parents = dbox_file_is_in_alt(file);
        file->fd = file->storage->v.
                file_create_fd(file, file->cur_path, create_parents);
-
-       /* even though we don't need it locked while writing to it, by the
-          time we rename() it it needs to be locked. so we might as well do
-          it here. */
-       if ((ret = dbox_file_try_lock(file)) <= 0) {
-               if (ret < 0)
-                       return -1;
-               mail_storage_set_critical(&file->storage->storage,
-                       "dbox: Couldn't lock created file: %s",
-                       file->cur_path);
-               return -1;
-       }
-       return 0;
+       return file->fd == -1 ? -1 : 0;
 }
 
 static struct dbox_file *
index 6f5226baa035705578f687c2e7687ed0f41bc954..bc09d51f26a211339e8e7037264daf6eeb8776a7 100644 (file)
@@ -638,7 +638,8 @@ dbox_map_find_existing_append(struct dbox_map_append_context *ctx,
                              uoff_t mail_size, struct ostream **output_r)
 {
        struct dbox_map *map = ctx->map;
-       struct dbox_file_append_context *const *file_appends;
+       struct dbox_file_append_context *const *file_appends, *append;
+       struct mdbox_file *mfile;
        unsigned int i, count;
        uoff_t append_offset;
 
@@ -648,13 +649,19 @@ dbox_map_find_existing_append(struct dbox_map_append_context *ctx,
        /* first try to use files already used in this append */
        file_appends = array_get(&ctx->file_appends, &count);
        for (i = count; i > ctx->files_nonappendable_count; i--) {
-               append_offset = file_appends[i-1]->output->offset;
-               if (append_offset + mail_size <= map->set->mdbox_rotate_size &&
-                   dbox_file_get_append_stream(file_appends[i-1], output_r) > 0)
-                       return file_appends[i-1];
+               append = file_appends[i-1];
 
-               /* can't append to this file anymore. we could close it
-                  otherwise, except that would also lose our lock too early. */
+               append_offset = append->output->offset;
+               if (append_offset + mail_size <= map->set->mdbox_rotate_size &&
+                   dbox_file_get_append_stream(append, output_r) > 0)
+                       return append;
+
+               /* can't append to this file anymore. if we created this file,
+                  close it so we don't waste fds. if we didn't, we can't close
+                  it without also losing our lock too early. */
+               mfile = (struct mdbox_file *)append->file;
+               if (mfile->file_id == 0 && dbox_file_append_flush(append) == 0)
+                       dbox_file_close(append->file);
        }
        ctx->files_nonappendable_count = count;
        return NULL;