Coda doesn't like cross-directory hardlinks. So try to fall back
on a plain rename instead.
close(fd);
ret = link(tmpfile, filename);
- if (ret < 0)
+ if (ret < 0) {
ret = errno;
+
+ /*
+ * Coda hack - coda doesn't like cross-directory links,
+ * so we fall back to a rename, which will mean that it
+ * won't be able to check collisions, but that's not a
+ * big deal.
+ *
+ * When this succeeds, we just return 0. We have nothing
+ * left to unlink.
+ */
+ if (ret == EXDEV && !rename(tmpfile, filename))
+ return 0;
+ }
unlink(tmpfile);
if (ret) {
if (ret != EEXIST) {