From: Timo Sirainen Date: Fri, 10 Apr 2009 22:38:36 +0000 (-0400) Subject: dbox: Flush file input caches when needed so that we don't try to use partially writt... X-Git-Tag: 2.0.alpha1~983 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5daeb99fd318c6bbd126c4769cb5d90f95a0a691;p=thirdparty%2Fdovecot%2Fcore.git dbox: Flush file input caches when needed so that we don't try to use partially written mails. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/dbox/dbox-file.c b/src/lib-storage/index/dbox/dbox-file.c index 44234d3592..6acb33da13 100644 --- a/src/lib-storage/index/dbox/dbox-file.c +++ b/src/lib-storage/index/dbox/dbox-file.c @@ -97,6 +97,18 @@ void dbox_files_free(struct dbox_storage *storage) array_clear(&storage->open_files); } +void dbox_files_sync_input(struct dbox_storage *storage) +{ + struct dbox_file *const *files; + unsigned int i, count; + + files = array_get(&storage->open_files, &count); + for (i = 0; i < count; i++) { + if (files[i]->input != NULL) + i_stream_sync(files[i]->input); + } +} + static void dbox_close_open_files(struct dbox_storage *storage, unsigned int close_count) { diff --git a/src/lib-storage/index/dbox/dbox-file.h b/src/lib-storage/index/dbox/dbox-file.h index b36dc65b62..d0c18637c4 100644 --- a/src/lib-storage/index/dbox/dbox-file.h +++ b/src/lib-storage/index/dbox/dbox-file.h @@ -127,6 +127,8 @@ void dbox_file_unref(struct dbox_file **file); /* Free all currently opened files. */ void dbox_files_free(struct dbox_storage *storage); +/* Flush all cached input data from opened files. */ +void dbox_files_sync_input(struct dbox_storage *storage); /* Assign a newly created file a new id. For single files assign UID, for multi files assign map UID. */ diff --git a/src/lib-storage/index/dbox/dbox-map.c b/src/lib-storage/index/dbox/dbox-map.c index 9dd2ff6657..981e3ee722 100644 --- a/src/lib-storage/index/dbox/dbox-map.c +++ b/src/lib-storage/index/dbox/dbox-map.c @@ -121,6 +121,11 @@ int dbox_map_refresh(struct dbox_map *map) struct mail_index_view_sync_ctx *ctx; bool delayed_expunges; + /* some open files may have read partially written mails. now that + map syncing makes the new mails visible, we need to make sure the + partial data is flushed out of memory */ + dbox_files_sync_input(map->storage); + if (mail_index_refresh(map->view->index) < 0) { mail_storage_set_internal_error(&map->storage->storage); mail_index_reset_error(map->index);