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.3.0.rc1~3112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c1f911643fd8542fb488bfe23a54000372cde80;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 344bf0206f..585abbccf8 100644 --- a/src/lib-fs/fs-api.c +++ b/src/lib-fs/fs-api.c @@ -719,11 +719,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(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); @@ -732,13 +730,26 @@ 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(file, output); va_end(args); } +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(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 f4cbfc0963..be4b800cef 100644 --- a/src/lib-fs/fs-api.h +++ b/src/lib-fs/fs-api.h @@ -276,6 +276,9 @@ int fs_write_stream_finish_async(struct fs_file *file); write. */ 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 663adad883..481bdcdbee 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -364,9 +364,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 e17aea586a..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,9 +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_error(_file->parent, &file->fs_output, - "fs_sis_try_link(%s) failed", - o_stream_get_name(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 85c194b99e..2dcfd1bb2a 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 f582c3bd54..d8fbcd8b6e 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; }