From: Aki Tuomi Date: Mon, 22 Aug 2016 06:42:26 +0000 (+0300) Subject: lib-fs: Add fs_write_stream_abort_parent and use it X-Git-Tag: 2.2.26~323 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb35c312367f8f658cce97667bc247b859e589dc;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-fs/fs-api.c b/src/lib-fs/fs-api.c index 49d099b439..bb46cffabe 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -272,7 +272,8 @@ void fs_file_close(struct fs_file *file) 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 @@ int fs_write_stream_finish_async(struct fs_file *file) 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 @@ void fs_write_stream_abort_error(struct fs_file *file, struct ostream **output, *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 @@ void fs_write_stream_abort(struct fs_file *file, struct ostream **output) 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) { diff --git a/src/lib-fs/fs-api.h b/src/lib-fs/fs-api.h index c1e7b3f699..6f1c67d491 100644 --- a/src/lib-fs/fs-api.h +++ b/src/lib-fs/fs-api.h @@ -277,6 +277,9 @@ int fs_write_stream_finish_async(struct fs_file *file); 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. */ diff --git a/src/lib-fs/fs-metawrap.c b/src/lib-fs/fs-metawrap.c index 75dff99386..f2d4acb346 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -365,9 +365,7 @@ static int fs_metawrap_write_stream_finish(struct fs_file *_file, bool success) 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); diff --git a/src/lib-fs/fs-sis-queue.c b/src/lib-fs/fs-sis-queue.c index 3936933355..a317a9aa83 100644 --- a/src/lib-fs/fs-sis-queue.c +++ b/src/lib-fs/fs-sis-queue.c @@ -149,10 +149,7 @@ static int fs_sis_queue_write_stream_finish(struct fs_file *_file, bool success) 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; } diff --git a/src/lib-fs/fs-sis.c b/src/lib-fs/fs-sis.c index d36daf5012..a806fa5609 100644 --- a/src/lib-fs/fs-sis.c +++ b/src/lib-fs/fs-sis.c @@ -287,10 +287,7 @@ static int fs_sis_write_stream_finish(struct fs_file *_file, bool success) 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 @@ static int fs_sis_write_stream_finish(struct fs_file *_file, bool success) 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; } } diff --git a/src/lib-fs/fs-wrapper.c b/src/lib-fs/fs-wrapper.c index 2b44c324e2..ee1f8aab4d 100644 --- a/src/lib-fs/fs-wrapper.c +++ b/src/lib-fs/fs-wrapper.c @@ -79,10 +79,7 @@ void fs_wrapper_write_stream(struct fs_file *file) 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; } diff --git a/src/plugins/fs-compress/fs-compress.c b/src/plugins/fs-compress/fs-compress.c index d0cd6ed7c6..5d6e527ed0 100644 --- a/src/plugins/fs-compress/fs-compress.c +++ b/src/plugins/fs-compress/fs-compress.c @@ -201,10 +201,7 @@ static int fs_compress_write_stream_finish(struct fs_file *_file, bool success) 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; }