Skip to content

Commit

Permalink
Fix sanity-check for hardlinks created during git clone
Browse files Browse the repository at this point in the history
At some filesystems, creation of hardlink may change inode
of source file. Such hardlinks should be accepted by git clone.
  • Loading branch information
ddzialak committed Oct 8, 2024
1 parent 777489f commit 7e1dcbf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,22 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
*/
if (lstat(dest->buf, &st))
die(_("hardlink cannot be checked at '%s'"), dest->buf);

if (st.st_ino != iter->st.st_ino) {
/* For some filesystems (for example overlayfs within docker),
* creating hardlink may change inode of source file, so to avoid false failure
* reload lstat of source file before doing sanity-check.
*/
if (lstat(src->buf, &iter->st))
die(_("after created hardlink, lstat on source failed '%s'"), src->buf);
}
if (st.st_mode != iter->st.st_mode ||
st.st_ino != iter->st.st_ino ||
st.st_dev != iter->st.st_dev ||
st.st_size != iter->st.st_size ||
st.st_uid != iter->st.st_uid ||
st.st_gid != iter->st.st_gid)
die(_("hardlink different from source at '%s'"), dest->buf);

continue;
}
if (option_local > 0)
Expand Down

0 comments on commit 7e1dcbf

Please sign in to comment.