about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--configure.ac12
-rw-r--r--src/libstore/optimise-store.cc9
2 files changed, 19 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index a2512cfe9274..f920b8c10e75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -120,6 +120,18 @@ AC_CHECK_HEADERS([sys/mount.h], [], [],
 AC_CHECK_FUNCS([lutimes])
 
 
+# Check whether the store optimiser can optimise symlinks.
+AC_MSG_CHECKING([whether it is possible to create a link to a symlink])
+ln -s bla tmp_link
+if ln tmp_link tmp_link2 2> /dev/null; then
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(CAN_LINK_SYMLINK, 1, [Whether link() works on symlinks.])
+else
+    AC_MSG_RESULT(no)
+fi
+rm -f tmp_link tmp_link2
+
+
 # Check for <locale>.
 AC_LANG_PUSH(C++)
 AC_CHECK_HEADERS([locale])
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index e5bfa332dcc7..486538bd29f6 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -62,8 +62,13 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path)
         return;
     }
     
-    /* We can hard link regular files and symlinks. */
-    if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) return;
+    /* We can hard link regular files and maybe symlinks. */
+    if (!S_ISREG(st.st_mode)
+#if CAN_LINK_SYMLINK
+        x
+        && !S_ISLNK(st.st_mode)
+#endif
+        ) return;
         
     /* Sometimes SNAFUs can cause files in the Nix store to be
        modified, in particular when running programs as root under