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>
This commit is contained in:
Junio C Hamano 2009-08-16 23:53:12 -07:00
Родитель b6986d8a75
Коммит da02ca508b
3 изменённых файлов: 18 добавлений и 5 удалений

Просмотреть файл

@ -469,7 +469,7 @@ extern int index_path(unsigned char *sha1, const char *path, struct stat *st, in
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
/* "careful lstat()" */
extern int check_path(const char *path, int len, struct stat *st);
extern int check_path(const char *path, int len, struct stat *st, int skiplen);
#define REFRESH_REALLY 0x0001 /* ignore_valid */
#define REFRESH_UNMERGED 0x0002 /* allow unmerged */

12
entry.c
Просмотреть файл

@ -177,11 +177,15 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
/*
* This is like 'lstat()', except it refuses to follow symlinks
* in the path.
* in the path, after skipping "skiplen".
*/
int check_path(const char *path, int len, struct stat *st)
int check_path(const char *path, int len, struct stat *st, int skiplen)
{
if (has_symlink_leading_path(path, len)) {
const char *slash = path + len;
while (path < slash && *slash != '/')
slash--;
if (!has_dirs_only_path(path, slash - path, skiplen)) {
errno = ENOENT;
return -1;
}
@ -201,7 +205,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
strcpy(path + len, ce->name);
len += ce_namelen(ce);
if (!check_path(path, len, &st)) {
if (!check_path(path, len, &st, state->base_dir_len)) {
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
if (!changed)
return 0;

Просмотреть файл

@ -48,4 +48,13 @@ test_expect_success \
'git checkout-index conflicting paths.' \
'test -f path0 && test -d path1 && test -f path1/file1'
test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
mkdir -p tar/get &&
ln -s tar/get there &&
echo first &&
git checkout-index -a -f --prefix=there/ &&
echo second &&
git checkout-index -a -f --prefix=there/
'
test_done