trunk hardlinks patch
Jerry Lundström <[email protected]> Tue, 17 May 2005 16:24:49 +0200
| Newsgroups | gmane.mail.imap.binc.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------060106080302090706030803
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
This patch adds --with/without-hardlinks option for NFS/AFS filesystems.
--
Jerry Lundström
Sektionen för IT och media, Stockholms universitet
+46 (0)8 16 19 99 / http://www.it.su.se
--------------060106080302090706030803
Content-Type: text/x-patch;
name="bincimap-trunk-hardlinks.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="bincimap-trunk-hardlinks.patch"
Index: bincimap.trunk/configure.in
===================================================================
--- bincimap.trunk/configure.in (revision 321)
+++ bincimap.trunk/configure.in (working copy)
@@ -37,6 +37,7 @@
BINC_CHECK_OPENSSL
BINC_CHECK_LARGEFILE
BINC_CHECK_F_NOTIFY
+BINC_CHECK_HARDLINKS
dnl Add some useful directives to the top and bottom of the config.h file
AH_TOP(#ifndef config_h_included
Index: bincimap.trunk/src/maildir.cc
===================================================================
--- bincimap.trunk/src/maildir.cc (revision 321)
+++ bincimap.trunk/src/maildir.cc (working copy)
@@ -594,6 +594,7 @@
string fileName = ss.str();
+#ifdef WITH_HARDLINKS
if (link(safeName.c_str(), fileName.c_str()) == 0) {
unlink(safeName.c_str());
m.setInternalDate(tv.tv_sec);
@@ -602,6 +603,22 @@
committedMessages[&m] = fileName;
break;
}
+#else
+ if (!symlink(safeName.c_str(), fileName.c_str())) {
+ if (!rename(safeName.c_str(), fileName.c_str())) {
+ unlink(safeName.c_str());
+ m.setInternalDate(tv.tv_sec);
+ m.setUnique(ssid.str());
+ m.setUID(0);
+ committedMessages[&m] = fileName;
+ break;
+ }
+ else
+ {
+ unlink(fileName.c_str());
+ }
+ }
+#endif
if (errno == EEXIST)
continue;
@@ -709,6 +726,7 @@
bool Maildir::fastCopy(Message &m, Mailbox &desttype,
const std::string &destname)
{
+#ifdef WITH_HARDLINKS
// At this point, fastCopy is broken because the creation time is
// equal for the two clones. The new clone must have a new creation
// time. Symlinks are a possibility, but they break if other Maildir
@@ -772,6 +790,9 @@
}
return true;
+#else
+ return false;
+#endif
}
//------------------------------------------------------------------------
Index: bincimap.trunk/config.h.in
===================================================================
--- bincimap.trunk/config.h.in (revision 321)
+++ bincimap.trunk/config.h.in (working copy)
@@ -43,6 +43,9 @@
/* Version number of package */
#undef VERSION
+/* Define to 1 if we can use hardlinks. */
+#undef WITH_HARDLINKS
+
/* Define to 1 if SSL support is included. */
#undef WITH_SSL
Index: bincimap.trunk/bincimap.m4
===================================================================
--- bincimap.trunk/bincimap.m4 (revision 321)
+++ bincimap.trunk/bincimap.m4 (working copy)
@@ -382,3 +382,22 @@
echo Ready to make.
]
)
+
+dnl Check if we should use hardlinks.
+AC_DEFUN([BINC_CHECK_HARDLINKS],
+ [
+ AC_ARG_WITH(hardlinks,
+ AC_HELP_STRING([--with-hardlinks], [Use hardlinks for locking and speedups (default)])
+AC_HELP_STRING([--without-hardlinks], [Don't use hardlinks (for NFS/AFS filesystems)]),
+ [ if [[ "x$withval" != "xno" ]]; then WITH_HARDLINKS=1; fi ],
+ WITH_HARDLINKS=1)
+
+ AC_MSG_CHECKING(wether to use hardlinks)
+ if [[ "x$WITH_HARDLINKS" != "x1" ]]; then
+ AC_MSG_RESULT(no)
+ else
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(WITH_HARDLINKS, 1, [Define to 1 if we can use hardlinks.])
+ fi
+ ]
+)
--------------060106080302090706030803--