Mercurial > dovecot > core-2.2
changeset 20678:ff73fdd0558d
lib-fs: Add fs_write_stream_abort_parent and use it
Will do all the things abort_error does, but leaves
error untouched. You are expected to set one yourself.
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Mon, 22 Aug 2016 09:42:26 +0300 |
parents | 617f9489d849 |
children | db81a0009a43 |
files | src/lib-fs/fs-api.c src/lib-fs/fs-api.h src/lib-fs/fs-metawrap.c src/lib-fs/fs-sis-queue.c src/lib-fs/fs-sis.c src/lib-fs/fs-wrapper.c src/plugins/fs-compress/fs-compress.c |
diffstat | 7 files changed, 26 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-fs/fs-api.c Tue Aug 23 10:53:28 2016 +0300 +++ b/src/lib-fs/fs-api.c Mon Aug 22 09:42:26 2016 +0300 @@ -272,7 +272,8 @@ if (file->copy_input != NULL) { i_stream_unref(&file->copy_input); - fs_write_stream_abort(file, &file->copy_output); + fs_write_stream_abort_error(file, &file->copy_output, "fs_file_close(%s)", + o_stream_get_name(file->copy_output)); } i_free_and_null(file->write_digest); if (file->fs->v.file_close != NULL) T_BEGIN { @@ -704,11 +705,9 @@ return fs_write_stream_finish_int(file, TRUE); } -void fs_write_stream_abort_error(struct fs_file *file, struct ostream **output, const char *error_fmt, ...) +static void fs_write_stream_abort_int(struct fs_file *file, struct ostream **output) { int ret; - va_list args; - va_start(args, error_fmt); i_assert(*output == file->output); i_assert(file->output != NULL); @@ -717,10 +716,16 @@ *output = NULL; o_stream_ignore_last_errors(file->output); /* make sure we don't have an old error lying around */ - fs_set_verror(file->fs, error_fmt, args); ret = fs_write_stream_finish_int(file, FALSE); i_assert(ret != 0); +} +void fs_write_stream_abort_error(struct fs_file *file, struct ostream **output, const char *error_fmt, ...) +{ + va_list args; + va_start(args, error_fmt); + fs_set_verror(file->fs, error_fmt, args); + fs_write_stream_abort_int(file, output); va_end(args); } @@ -729,6 +734,13 @@ fs_write_stream_abort_error(file, output, "Write aborted"); } +void fs_write_stream_abort_parent(struct fs_file *file, struct ostream **output) +{ + i_assert(file->parent != NULL); + i_assert(fs_filelast_error(file->parent) != NULL); + fs_write_stream_abort_int(file, output); +} + void fs_write_set_hash(struct fs_file *file, const struct hash_method *method, const void *digest) {
--- a/src/lib-fs/fs-api.h Tue Aug 23 10:53:28 2016 +0300 +++ b/src/lib-fs/fs-api.h Mon Aug 22 09:42:26 2016 +0300 @@ -277,6 +277,9 @@ void fs_write_stream_abort(struct fs_file *file, struct ostream **output); void fs_write_stream_abort_error(struct fs_file *file, struct ostream **output, const char *error_fmt, ...) ATTR_FORMAT(3, 4); +/* Same as above, except it closes the *parent* file and error is left untouched */ +void fs_write_stream_abort_parent(struct fs_file *file, struct ostream **output); + /* 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 implemented by Content-MD5 header. */
--- a/src/lib-fs/fs-metawrap.c Tue Aug 23 10:53:28 2016 +0300 +++ b/src/lib-fs/fs-metawrap.c Mon Aug 22 09:42:26 2016 +0300 @@ -365,9 +365,7 @@ if (file->super_output != NULL) { /* no metawrap */ i_assert(file->temp_output == NULL); - fs_write_stream_abort_error(_file->parent, &file->super_output, "error(%s): %s", - o_stream_get_name(file->super_output), - o_stream_get_error(file->super_output)); + fs_write_stream_abort_parent(_file->parent, &file->super_output); } else { i_assert(file->temp_output != NULL); o_stream_destroy(&file->temp_output);
--- a/src/lib-fs/fs-sis-queue.c Tue Aug 23 10:53:28 2016 +0300 +++ b/src/lib-fs/fs-sis-queue.c Mon Aug 22 09:42:26 2016 +0300 @@ -149,10 +149,7 @@ if (!success) { if (_file->parent != NULL) - fs_write_stream_abort_error(_file->parent, &_file->output, - "write(%s) failed: %s", - o_stream_get_name(_file->output), - o_stream_get_error(_file->output)); + fs_write_stream_abort_parent(_file->parent, &_file->output); return -1; }
--- a/src/lib-fs/fs-sis.c Tue Aug 23 10:53:28 2016 +0300 +++ b/src/lib-fs/fs-sis.c Mon Aug 22 09:42:26 2016 +0300 @@ -287,10 +287,7 @@ if (!success) { if (_file->parent != NULL) - fs_write_stream_abort_error(_file->parent, &file->fs_output, - "write(%s) error: %s", - o_stream_get_name(file->fs_output), - o_stream_get_error(file->fs_output)); + fs_write_stream_abort_parent(_file->parent, &file->fs_output); o_stream_unref(&_file->output); return -1; } @@ -300,7 +297,7 @@ i_stream_is_eof(file->hash_input)) { o_stream_unref(&_file->output); if (fs_sis_try_link(file)) { - fs_write_stream_abort(_file->parent, &file->fs_output); + fs_write_stream_abort_parent(_file->parent, &file->fs_output); return 1; } }
--- a/src/lib-fs/fs-wrapper.c Tue Aug 23 10:53:28 2016 +0300 +++ b/src/lib-fs/fs-wrapper.c Mon Aug 22 09:42:26 2016 +0300 @@ -79,10 +79,7 @@ int fs_wrapper_write_stream_finish(struct fs_file *file, bool success) { if (!success) { - fs_write_stream_abort_error(file->parent, &file->output, - "write(%s) failed: %s", - o_stream_get_name(file->output), - o_stream_get_error(file->output)); + fs_write_stream_abort_parent(file->parent, &file->output); return -1; }
--- a/src/plugins/fs-compress/fs-compress.c Tue Aug 23 10:53:28 2016 +0300 +++ b/src/plugins/fs-compress/fs-compress.c Mon Aug 22 09:42:26 2016 +0300 @@ -201,10 +201,7 @@ if (file->temp_output != NULL) o_stream_destroy(&file->temp_output); if (file->super_output != NULL) - fs_write_stream_abort_error(_file->parent, &file->super_output, - "write(%s) failed: %s", - o_stream_get_name(file->super_output), - o_stream_get_error(file->super_output)); + fs_write_stream_abort_parent(_file->parent, &file->super_output); return -1; }