dovecot-2.2: fs-posix: fs_copy() no longer fails if destination ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 25 23:04:17 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/d50151444c9a
changeset: 18024:d50151444c9a
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 26 02:03:22 2014 +0300
description:
fs-posix: fs_copy() no longer fails if destination exists and FS_OPEN_MODE_REPLACE is used

diffstat:

 src/lib-fs/fs-posix.c |  7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diffs (22 lines):

diff -r 5cd30ecff35d -r d50151444c9a src/lib-fs/fs-posix.c
--- a/src/lib-fs/fs-posix.c	Sun Oct 26 01:59:05 2014 +0300
+++ b/src/lib-fs/fs-posix.c	Sun Oct 26 02:03:22 2014 +0300
@@ -610,11 +610,18 @@
 
 static int fs_posix_copy(struct fs_file *_src, struct fs_file *_dest)
 {
+	struct posix_fs_file *dest = (struct posix_fs_file *)_dest;
 	struct posix_fs *fs = (struct posix_fs *)_src->fs;
 	unsigned int try_count = 0;
 	int ret;
 
 	ret = link(_src->path, _dest->path);
+	if (errno == EEXIST && dest->open_mode == FS_OPEN_MODE_REPLACE) {
+		/* destination file already exists - replace it */
+		if (unlink(_dest->path) < 0 && errno != ENOENT)
+			i_error("unlink(%s) failed: %m", _dest->path);
+		ret = link(_src->path, _dest->path);
+	}
 	while (ret < 0 && errno == ENOENT &&
 	       try_count <= MAX_MKDIR_RETRY_COUNT) {
 		if (fs_posix_mkdir_parents(fs, _dest->path) < 0)


More information about the dovecot-cvs mailing list