diff src/lib/nfs-workarounds.c @ 6813:575235932194 HEAD

nfs_safe_link(): Support linking files without original link count=1. Use it when copying maildir files, but only if mail_nfs_storage=yes.
author Timo Sirainen <tss@iki.fi>
date Fri, 16 Nov 2007 03:50:15 +0200
parents 9bc620b934f4
children 8573124a89b3
line wrap: on
line diff
--- a/src/lib/nfs-workarounds.c	Thu Nov 15 16:27:53 2007 +0200
+++ b/src/lib/nfs-workarounds.c	Fri Nov 16 03:50:15 2007 +0200
@@ -129,16 +129,17 @@
 	return nfs_safe_do(path, nfs_safe_lstat_callback, buf);
 }
 
-int nfs_safe_link(const char *oldpath, const char *newpath)
+int nfs_safe_link(const char *oldpath, const char *newpath, bool links1)
 {
 	struct stat st;
+	nlink_t orig_link_count = 1;
 
-#ifdef DEBUG
-	if (stat(oldpath, &st) == 0 && st.st_nlink != 1) {
-		i_panic("nfs_safe_link(): %s link count = %d",
-			oldpath, (int)st.st_nlink);
+	if (!links1) {
+		if (stat(oldpath, &st) < 0)
+			return -1;
+		orig_link_count = st.st_nlink;
 	}
-#endif
+
 	if (link(oldpath, newpath) == 0) {
 #ifndef __FreeBSD__
 		return 0;
@@ -151,7 +152,7 @@
 	/* We don't know if it succeeded or failed. stat() to make sure. */
 	if (stat(oldpath, &st) < 0)
 		return -1;
-	if (st.st_nlink < 2) {
+	if (st.st_nlink == orig_link_count) {
 		errno = EEXIST;
 		return -1;
 	}