@matheusbsbs / matheus-bagliano / commits / da02ca508b
Fork 0

check_path(): allow symlinked directories to checkout-index --prefix

Merlyn noticed that Documentation/install-doc-quick.sh no longer correctly removes old installed documents when the target directory has a leading path that is a symlink. It turns out that "checkout-index --prefix" was broken by recent b6986d8 (git-checkout: be careful about untracked symlinks, 2009-07-29). I suspect has_symlink_leading_path() could learn the third parameter (prefix that is allowed to be symlinked directories) to allow us to retire a similar function has_dirs_only_path(). Another avenue of fixing this I considered was to get rid of base_dir and base_dir_len from "struct checkout", and instead make "git checkout-index" when run with --prefix mkdir the leading path and chdir in there. It might be the best longer term solution to this issue, as the base_dir feature is used only by that rather obscure codepath as far as I know. But at least this patch should fix this breakage. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 16, 2009 at 23:53 UTC da02ca508b842e61c71d920310ff30bbe0238993
3 files changed +18 -5
cache.h
+1 -1
@@ -469,7 +469,7 @@ extern int index_path(unsigned char *sha1, const char *path, struct stat *st, in
469 extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
470
471 /* "careful lstat()" */
472 -extern int check_path(const char *path, int len, struct stat *st);
472 +extern int check_path(const char *path, int len, struct stat *st, int skiplen);
473
474 #define REFRESH_REALLY 0x0001 /* ignore_valid */
475 #define REFRESH_UNMERGED 0x0002 /* allow unmerged */
entry.c
+8 -4
@@ -177,11 +177,15 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
177
178 /*
179 * This is like 'lstat()', except it refuses to follow symlinks
180 - * in the path.
180 + * in the path, after skipping "skiplen".
181 */
182 -int check_path(const char *path, int len, struct stat *st)
182 +int check_path(const char *path, int len, struct stat *st, int skiplen)
183 {
184 - if (has_symlink_leading_path(path, len)) {
184 + const char *slash = path + len;
185 +
186 + while (path < slash && *slash != '/')
187 + slash--;
188 + if (!has_dirs_only_path(path, slash - path, skiplen)) {
189 errno = ENOENT;
190 return -1;
191 }
@@ -201,7 +205,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
205 strcpy(path + len, ce->name);
206 len += ce_namelen(ce);
207
204 - if (!check_path(path, len, &st)) {
208 + if (!check_path(path, len, &st, state->base_dir_len)) {
209 unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
210 if (!changed)
211 return 0;
t/t2000-checkout-cache-clash.sh
+9
@@ -48,4 +48,13 @@ test_expect_success \
48 'git checkout-index conflicting paths.' \
49 'test -f path0 && test -d path1 && test -f path1/file1'
50
51 +test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
52 + mkdir -p tar/get &&
53 + ln -s tar/get there &&
54 + echo first &&
55 + git checkout-index -a -f --prefix=there/ &&
56 + echo second &&
57 + git checkout-index -a -f --prefix=there/
58 +'
59 +
60 test_done