Skip to content

Commit a31c6d0

Browse files
author
Linus Torvalds
committed
sha1_file: make the new sha1 object writing be coda-friendly.
Coda doesn't like cross-directory hardlinks. So try to fall back on a plain rename instead.
1 parent aac1794 commit a31c6d0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sha1_file.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,21 @@ int write_sha1_file(char *buf, unsigned long len, const char *type, unsigned cha
353353
close(fd);
354354

355355
ret = link(tmpfile, filename);
356-
if (ret < 0)
356+
if (ret < 0) {
357357
ret = errno;
358+
359+
/*
360+
* Coda hack - coda doesn't like cross-directory links,
361+
* so we fall back to a rename, which will mean that it
362+
* won't be able to check collisions, but that's not a
363+
* big deal.
364+
*
365+
* When this succeeds, we just return 0. We have nothing
366+
* left to unlink.
367+
*/
368+
if (ret == EXDEV && !rename(tmpfile, filename))
369+
return 0;
370+
}
358371
unlink(tmpfile);
359372
if (ret) {
360373
if (ret != EEXIST) {

0 commit comments

Comments
 (0)