From a0cf7d3924dec409e6eadaf3237fcecd4194ec75 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 1 Jun 2016 17:06:28 +0300 Subject: [PATCH] lib-fs: Clarified fs_write_stream_abort() API and dropped its _async(). We can't handle an abort after an async fs_write_stream_finish() is already going. --- src/lib-fs/fs-api-private.h | 2 ++ src/lib-fs/fs-api.c | 17 +++++++---------- src/lib-fs/fs-api.h | 7 +++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/lib-fs/fs-api-private.h b/src/lib-fs/fs-api-private.h index 5e152988a8..8889e6fd3a 100644 --- a/src/lib-fs/fs-api-private.h +++ b/src/lib-fs/fs-api-private.h @@ -48,6 +48,8 @@ struct fs_vfuncs { int (*write)(struct fs_file *file, const void *data, size_t size); void (*write_stream)(struct fs_file *file); + /* After write_stream_finish() is called once, all the following + (async) calls will have success==TRUE. */ int (*write_stream_finish)(struct fs_file *file, bool success); int (*lock)(struct fs_file *file, unsigned int secs, diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c index d371a604d7..97551be7ea 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -697,21 +697,18 @@ int fs_write_stream_finish_async(struct fs_file *file) void fs_write_stream_abort(struct fs_file *file, struct ostream **output) { + int ret; + i_assert(*output == file->output); + i_assert(file->output != NULL); + i_assert(output != &file->output); *output = NULL; - if (file->output != NULL) - o_stream_ignore_last_errors(file->output); + o_stream_ignore_last_errors(file->output); /* make sure we don't have an old error lying around */ fs_set_error(file->fs, "Write aborted"); - (void)fs_write_stream_finish_int(file, FALSE); -} - -void fs_write_stream_abort_async(struct fs_file *file) -{ - i_assert(file->output == NULL); - - fs_write_stream_abort(file, &file->output); + ret = fs_write_stream_finish_int(file, FALSE); + i_assert(ret != 0); } void fs_write_set_hash(struct fs_file *file, const struct hash_method *method, diff --git a/src/lib-fs/fs-api.h b/src/lib-fs/fs-api.h index 92a32fc5f4..d5702533f8 100644 --- a/src/lib-fs/fs-api.h +++ b/src/lib-fs/fs-api.h @@ -268,11 +268,10 @@ int fs_write_stream_finish(struct fs_file *file, struct ostream **output); int fs_write_stream_finish_async(struct fs_file *file); /* Abort writing via stream. Anything written to the stream is discarded. o_stream_ignore_last_errors() is called on the output stream so the caller - doesn't need to do it. */ + doesn't need to do it. This must not be called after + fs_write_stream_finish(), i.e. it can't be used to abort a pending async + write. */ void fs_write_stream_abort(struct fs_file *file, struct ostream **output); -/* Abort writing to a stream after fs_write_stream_finish() was already - called. */ -void fs_write_stream_abort_async(struct fs_file *file); /* Set a hash to the following write. The storage can then verify that the input data matches the specified hash, or fail if it doesn't. Typically -- 2.47.3