dovecot-2.2: fs-posix: Make sure the file isn't attempted to be ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Mar 9 13:42:56 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/966680fbe2a9
changeset: 18309:966680fbe2a9
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Mar 09 15:26:01 2015 +0200
description:
fs-posix: Make sure the file isn't attempted to be opened for reading while it's being written.
Also if the write failed, the read should fail.

diffstat:

 src/lib-fs/fs-posix.c |  26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diffs (54 lines):

diff -r 1f0428d0fece -r 966680fbe2a9 src/lib-fs/fs-posix.c
--- a/src/lib-fs/fs-posix.c	Fri Mar 06 17:47:38 2015 +0200
+++ b/src/lib-fs/fs-posix.c	Mon Mar 09 15:26:01 2015 +0200
@@ -312,14 +312,24 @@
 	i_free(file);
 }
 
+static int fs_posix_open_for_read(struct posix_fs_file *file)
+{
+	i_assert(file->file.output == NULL);
+	i_assert(file->temp_path == NULL);
+
+	if (file->fd == -1) {
+		if (fs_posix_open(file) < 0)
+			return -1;
+	}
+	return 0;
+}
+
 static bool fs_posix_prefetch(struct fs_file *_file, uoff_t length ATTR_UNUSED)
 {
 	struct posix_fs_file *file = (struct posix_fs_file *)_file;
 
-	if (file->fd == -1) {
-		if (fs_posix_open(file) < 0)
-			return TRUE;
-	}
+	if (fs_posix_open_for_read(file) < 0)
+		return TRUE;
 
 /* HAVE_POSIX_FADVISE alone isn't enough for CentOS 4.9 */
 #if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
@@ -336,10 +346,8 @@
 	struct posix_fs_file *file = (struct posix_fs_file *)_file;
 	ssize_t ret;
 
-	if (file->fd == -1) {
-		if (fs_posix_open(file) < 0)
-			return -1;
-	}
+	if (fs_posix_open_for_read(file) < 0)
+		return -1;
 
 	if (file->seek_to_beginning) {
 		file->seek_to_beginning = FALSE;
@@ -363,7 +371,7 @@
 	struct posix_fs_file *file = (struct posix_fs_file *)_file;
 	struct istream *input;
 
-	if (file->fd == -1 && fs_posix_open(file) < 0)
+	if (fs_posix_open_for_read(file) < 0)
 		input = i_stream_create_error_str(errno, "%s", fs_last_error(_file->fs));
 	else {
 		/* the stream could live even after the fs_file */


More information about the dovecot-cvs mailing list