From: Timo Sirainen Date: Sun, 16 Aug 2015 11:10:48 +0000 (+0200) Subject: lib-fs: Small code cleanup for handling write_stream_finish() X-Git-Tag: 2.2.19.rc1~259 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=825e349a826ee2a984069edf394460bed5bc3426;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: Small code cleanup for handling write_stream_finish() --- diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c index 1e8c75856e..00f9d783a1 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -555,9 +555,25 @@ struct ostream *fs_write_stream(struct fs_file *file) return file->output; } -int fs_write_stream_finish(struct fs_file *file, struct ostream **output) +static int fs_write_stream_finish_int(struct fs_file *file, bool success) { int ret; + + T_BEGIN { + ret = file->fs->v.write_stream_finish(file, success); + } T_END; + if (ret == 0) { + file->metadata_changed = FALSE; + } else { + /* write didn't finish yet. this shouldn't happen if we + indicated a failure. */ + i_assert(success); + } + return ret; +} + +int fs_write_stream_finish(struct fs_file *file, struct ostream **output) +{ bool success = TRUE; i_assert(*output == file->output || *output == NULL); @@ -573,24 +589,12 @@ int fs_write_stream_finish(struct fs_file *file, struct ostream **output) success = FALSE; } } - T_BEGIN { - ret = file->fs->v.write_stream_finish(file, success); - } T_END; - if (ret != 0) - file->metadata_changed = FALSE; - return ret; + return fs_write_stream_finish_int(file, success); } int fs_write_stream_finish_async(struct fs_file *file) { - int ret; - - T_BEGIN { - ret = file->fs->v.write_stream_finish(file, TRUE); - } T_END; - if (ret != 0) - file->metadata_changed = FALSE; - return ret; + return fs_write_stream_finish_int(file, TRUE); } void fs_write_stream_abort(struct fs_file *file, struct ostream **output) @@ -600,10 +604,7 @@ void fs_write_stream_abort(struct fs_file *file, struct ostream **output) *output = NULL; if (file->output != NULL) o_stream_ignore_last_errors(file->output); - T_BEGIN { - (void)file->fs->v.write_stream_finish(file, FALSE); - } T_END; - file->metadata_changed = FALSE; + (void)fs_write_stream_finish_int(file, FALSE); } void fs_write_set_hash(struct fs_file *file, const struct hash_method *method,