summaryrefslogtreecommitdiff
path: root/entry.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-07-29 20:22:25 -0700
committerJunio C Hamano <gitster@pobox.com>2009-07-29 20:24:28 -0700
commitb6986d8a75812a003a1623e0f0dff93c4a026b44 (patch)
tree310d937efb0c261707bd5577f696270c9b1d068f /entry.c
parent77716755cbdf970fa0814a5f77c884b1f17693de (diff)
downloadgit-b6986d8a75812a003a1623e0f0dff93c4a026b44.tar.gz
git-checkout: be careful about untracked symlinks
This fixes the case where an untracked symlink that points at a directory with tracked paths confuses the checkout logic, demostrated in t6035. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'entry.c')
-rw-r--r--entry.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/entry.c b/entry.c
index d3e86c722a..f276cf3b88 100644
--- a/entry.c
+++ b/entry.c
@@ -175,6 +175,19 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
return 0;
}
+/*
+ * This is like 'lstat()', except it refuses to follow symlinks
+ * in the path.
+ */
+int check_path(const char *path, int len, struct stat *st)
+{
+ if (has_symlink_leading_path(path, len)) {
+ errno = ENOENT;
+ return -1;
+ }
+ return lstat(path, st);
+}
+
int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath)
{
static char path[PATH_MAX + 1];
@@ -188,7 +201,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
strcpy(path + len, ce->name);
len += ce_namelen(ce);
- if (!lstat(path, &st)) {
+ if (!check_path(path, len, &st)) {
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
if (!changed)
return 0;