dovecot-2.2: lib-fs: Added a default fs_write() implementation u...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Dec 4 07:04:42 EET 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/bde65904d980
changeset: 15446:bde65904d980
user: Timo Sirainen <tss at iki.fi>
date: Tue Dec 04 07:04:32 2012 +0200
description:
lib-fs: Added a default fs_write() implementation using the fs_write_stream*().
diffstat:
src/lib-fs/fs-api-private.h | 1 +
src/lib-fs/fs-api.c | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 1 deletions(-)
diffs (61 lines):
diff -r 8f0af55ee4b6 -r bde65904d980 src/lib-fs/fs-api-private.h
--- a/src/lib-fs/fs-api-private.h Tue Dec 04 05:39:36 2012 +0200
+++ b/src/lib-fs/fs-api-private.h Tue Dec 04 07:04:32 2012 +0200
@@ -64,6 +64,7 @@
struct fs *fs;
struct ostream *output;
char *path;
+ bool write_pending;
};
struct fs_lock {
diff -r 8f0af55ee4b6 -r bde65904d980 src/lib-fs/fs-api.c
--- a/src/lib-fs/fs-api.c Tue Dec 04 05:39:36 2012 +0200
+++ b/src/lib-fs/fs-api.c Tue Dec 04 07:04:32 2012 +0200
@@ -4,6 +4,7 @@
#include "array.h"
#include "module-dir.h"
#include "str.h"
+#include "ostream.h"
#include "fs-api-private.h"
static struct module *fs_modules = NULL;
@@ -208,7 +209,37 @@
int fs_write(struct fs_file *file, const void *data, size_t size)
{
- return file->fs->v.write(file, data, size);
+ struct ostream *output;
+ ssize_t ret;
+ int err;
+
+ if (file->fs->v.write != NULL)
+ return file->fs->v.write(file, data, size);
+
+ /* backend didn't bother to implement write(), but we can do it with
+ streams. */
+ if (!file->write_pending) {
+ output = fs_write_stream(file);
+ if ((ret = o_stream_send(output, data, size)) < 0) {
+ err = errno;
+ fs_set_error(file->fs, "fs_write(%s) failed: %m",
+ o_stream_get_name(output));
+ fs_write_stream_abort(file, &output);
+ errno = err;
+ return -1;
+ }
+ i_assert((size_t)ret == size);
+ ret = fs_write_stream_finish(file, &output);
+ } else {
+ ret = fs_write_stream_finish_async(file);
+ }
+ if (ret == 0) {
+ fs_set_error_async(file->fs);
+ file->write_pending = TRUE;
+ return -1;
+ }
+ file->write_pending = FALSE;
+ return ret < 0 ? -1 : 0;
}
struct ostream *fs_write_stream(struct fs_file *file)
More information about the dovecot-cvs
mailing list