Mercurial > dovecot > core-2.2
changeset 20237:7f346855509b
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.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Wed, 01 Jun 2016 17:06:28 +0300 |
parents | 783dd10f3dcf |
children | d9ed3a90b50e |
files | src/lib-fs/fs-api-private.h src/lib-fs/fs-api.c src/lib-fs/fs-api.h |
diffstat | 3 files changed, 12 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-fs/fs-api-private.h Wed Jun 01 15:15:19 2016 +0300 +++ b/src/lib-fs/fs-api-private.h Wed Jun 01 17:06:28 2016 +0300 @@ -48,6 +48,8 @@ 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,
--- a/src/lib-fs/fs-api.c Wed Jun 01 15:15:19 2016 +0300 +++ b/src/lib-fs/fs-api.c Wed Jun 01 17:06:28 2016 +0300 @@ -682,21 +682,18 @@ 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,
--- a/src/lib-fs/fs-api.h Wed Jun 01 15:15:19 2016 +0300 +++ b/src/lib-fs/fs-api.h Wed Jun 01 17:06:28 2016 +0300 @@ -268,11 +268,10 @@ 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