diff options
author | Clemens Buchacher <drizzd@aon.at> | 2010-10-09 15:53:00 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-10-13 14:34:09 -0700 |
commit | f66caaf9c8e0feb840a439a58e165b963aec79cf (patch) | |
tree | 0c0f99ba5a023b7330b949045ba188e3a7cc1fde /symlinks.c | |
parent | 4856ff2a195e558c82ca3cab636c4d4fbef148e3 (diff) | |
download | git-f66caaf9c8e0feb840a439a58e165b963aec79cf.tar.gz |
do not overwrite files in leading path
If the work tree contains an untracked file x, and
unpack-trees wants to checkout a path x/*, the
file x is removed unconditionally.
Instead, apply the same checks that are normally
used for untracked files, and abort if the file
cannot be removed.
Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Diffstat (limited to 'symlinks.c')
-rw-r--r-- | symlinks.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/symlinks.c b/symlinks.c index b7343ebd62..3cacebd91a 100644 --- a/symlinks.c +++ b/symlinks.c @@ -209,15 +209,26 @@ int has_symlink_leading_path(const char *name, int len) } /* - * Return non-zero if path 'name' has a leading symlink component or + * Return zero if path 'name' has a leading symlink component or * if some leading path component does not exists. + * + * Return -1 if leading path exists and is a directory. + * + * Return path length if leading path exists and is neither a + * directory nor a symlink. */ -int has_symlink_or_noent_leading_path(const char *name, int len) +int check_leading_path(const char *name, int len) { struct cache_def *cache = &default_cache; /* FIXME */ - return lstat_cache(cache, name, len, - FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT) & - (FL_SYMLINK|FL_NOENT); + int flags; + int match_len = lstat_cache_matchlen(cache, name, len, &flags, + FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT); + if (flags & (FL_SYMLINK|FL_NOENT)) + return 0; + else if (flags & FL_DIR) + return -1; + else + return match_len; } /* |