Merge branch 'kb/path-max-must-go'
* kb/path-max-must-go: symlinks: remove PATH_MAX limitationmaint
commit
11def366e5
8
cache.h
8
cache.h
|
@ -1090,12 +1090,16 @@ struct checkout {
|
||||||
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
|
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
|
||||||
|
|
||||||
struct cache_def {
|
struct cache_def {
|
||||||
char path[PATH_MAX + 1];
|
struct strbuf path;
|
||||||
int len;
|
|
||||||
int flags;
|
int flags;
|
||||||
int track_flags;
|
int track_flags;
|
||||||
int prefix_len_stat_func;
|
int prefix_len_stat_func;
|
||||||
};
|
};
|
||||||
|
#define CACHE_DEF_INIT { STRBUF_INIT, 0, 0, 0 }
|
||||||
|
static inline void cache_def_free(struct cache_def *cache)
|
||||||
|
{
|
||||||
|
strbuf_release(&cache->path);
|
||||||
|
}
|
||||||
|
|
||||||
extern int has_symlink_leading_path(const char *name, int len);
|
extern int has_symlink_leading_path(const char *name, int len);
|
||||||
extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
|
extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
|
||||||
|
|
|
@ -37,9 +37,8 @@ static void *preload_thread(void *_data)
|
||||||
struct thread_data *p = _data;
|
struct thread_data *p = _data;
|
||||||
struct index_state *index = p->index;
|
struct index_state *index = p->index;
|
||||||
struct cache_entry **cep = index->cache + p->offset;
|
struct cache_entry **cep = index->cache + p->offset;
|
||||||
struct cache_def cache;
|
struct cache_def cache = CACHE_DEF_INIT;
|
||||||
|
|
||||||
memset(&cache, 0, sizeof(cache));
|
|
||||||
nr = p->nr;
|
nr = p->nr;
|
||||||
if (nr + p->offset > index->cache_nr)
|
if (nr + p->offset > index->cache_nr)
|
||||||
nr = index->cache_nr - p->offset;
|
nr = index->cache_nr - p->offset;
|
||||||
|
@ -64,6 +63,7 @@ static void *preload_thread(void *_data)
|
||||||
continue;
|
continue;
|
||||||
ce_mark_uptodate(ce);
|
ce_mark_uptodate(ce);
|
||||||
} while (--nr > 0);
|
} while (--nr > 0);
|
||||||
|
cache_def_free(&cache);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
63
symlinks.c
63
symlinks.c
|
@ -35,12 +35,11 @@ static int longest_path_match(const char *name_a, int len_a,
|
||||||
return match_len;
|
return match_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cache_def default_cache;
|
static struct cache_def default_cache = CACHE_DEF_INIT;
|
||||||
|
|
||||||
static inline void reset_lstat_cache(struct cache_def *cache)
|
static inline void reset_lstat_cache(struct cache_def *cache)
|
||||||
{
|
{
|
||||||
cache->path[0] = '\0';
|
strbuf_reset(&cache->path);
|
||||||
cache->len = 0;
|
|
||||||
cache->flags = 0;
|
cache->flags = 0;
|
||||||
/*
|
/*
|
||||||
* The track_flags and prefix_len_stat_func members is only
|
* The track_flags and prefix_len_stat_func members is only
|
||||||
|
@ -73,7 +72,7 @@ static int lstat_cache_matchlen(struct cache_def *cache,
|
||||||
int prefix_len_stat_func)
|
int prefix_len_stat_func)
|
||||||
{
|
{
|
||||||
int match_len, last_slash, last_slash_dir, previous_slash;
|
int match_len, last_slash, last_slash_dir, previous_slash;
|
||||||
int save_flags, max_len, ret;
|
int save_flags, ret;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (cache->track_flags != track_flags ||
|
if (cache->track_flags != track_flags ||
|
||||||
|
@ -93,14 +92,14 @@ static int lstat_cache_matchlen(struct cache_def *cache,
|
||||||
* the 2 "excluding" path types.
|
* the 2 "excluding" path types.
|
||||||
*/
|
*/
|
||||||
match_len = last_slash =
|
match_len = last_slash =
|
||||||
longest_path_match(name, len, cache->path, cache->len,
|
longest_path_match(name, len, cache->path.buf,
|
||||||
&previous_slash);
|
cache->path.len, &previous_slash);
|
||||||
*ret_flags = cache->flags & track_flags & (FL_NOENT|FL_SYMLINK);
|
*ret_flags = cache->flags & track_flags & (FL_NOENT|FL_SYMLINK);
|
||||||
|
|
||||||
if (!(track_flags & FL_FULLPATH) && match_len == len)
|
if (!(track_flags & FL_FULLPATH) && match_len == len)
|
||||||
match_len = last_slash = previous_slash;
|
match_len = last_slash = previous_slash;
|
||||||
|
|
||||||
if (*ret_flags && match_len == cache->len)
|
if (*ret_flags && match_len == cache->path.len)
|
||||||
return match_len;
|
return match_len;
|
||||||
/*
|
/*
|
||||||
* If we now have match_len > 0, we would know that
|
* If we now have match_len > 0, we would know that
|
||||||
|
@ -121,21 +120,22 @@ static int lstat_cache_matchlen(struct cache_def *cache,
|
||||||
*/
|
*/
|
||||||
*ret_flags = FL_DIR;
|
*ret_flags = FL_DIR;
|
||||||
last_slash_dir = last_slash;
|
last_slash_dir = last_slash;
|
||||||
max_len = len < PATH_MAX ? len : PATH_MAX;
|
if (len > cache->path.len)
|
||||||
while (match_len < max_len) {
|
strbuf_grow(&cache->path, len - cache->path.len);
|
||||||
|
while (match_len < len) {
|
||||||
do {
|
do {
|
||||||
cache->path[match_len] = name[match_len];
|
cache->path.buf[match_len] = name[match_len];
|
||||||
match_len++;
|
match_len++;
|
||||||
} while (match_len < max_len && name[match_len] != '/');
|
} while (match_len < len && name[match_len] != '/');
|
||||||
if (match_len >= max_len && !(track_flags & FL_FULLPATH))
|
if (match_len >= len && !(track_flags & FL_FULLPATH))
|
||||||
break;
|
break;
|
||||||
last_slash = match_len;
|
last_slash = match_len;
|
||||||
cache->path[last_slash] = '\0';
|
cache->path.buf[last_slash] = '\0';
|
||||||
|
|
||||||
if (last_slash <= prefix_len_stat_func)
|
if (last_slash <= prefix_len_stat_func)
|
||||||
ret = stat(cache->path, &st);
|
ret = stat(cache->path.buf, &st);
|
||||||
else
|
else
|
||||||
ret = lstat(cache->path, &st);
|
ret = lstat(cache->path.buf, &st);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
*ret_flags = FL_LSTATERR;
|
*ret_flags = FL_LSTATERR;
|
||||||
|
@ -158,12 +158,11 @@ static int lstat_cache_matchlen(struct cache_def *cache,
|
||||||
* for the moment!
|
* for the moment!
|
||||||
*/
|
*/
|
||||||
save_flags = *ret_flags & track_flags & (FL_NOENT|FL_SYMLINK);
|
save_flags = *ret_flags & track_flags & (FL_NOENT|FL_SYMLINK);
|
||||||
if (save_flags && last_slash > 0 && last_slash <= PATH_MAX) {
|
if (save_flags && last_slash > 0) {
|
||||||
cache->path[last_slash] = '\0';
|
cache->path.buf[last_slash] = '\0';
|
||||||
cache->len = last_slash;
|
cache->path.len = last_slash;
|
||||||
cache->flags = save_flags;
|
cache->flags = save_flags;
|
||||||
} else if ((track_flags & FL_DIR) &&
|
} else if ((track_flags & FL_DIR) && last_slash_dir > 0) {
|
||||||
last_slash_dir > 0 && last_slash_dir <= PATH_MAX) {
|
|
||||||
/*
|
/*
|
||||||
* We have a separate test for the directory case,
|
* We have a separate test for the directory case,
|
||||||
* since it could be that we have found a symlink or a
|
* since it could be that we have found a symlink or a
|
||||||
|
@ -175,8 +174,8 @@ static int lstat_cache_matchlen(struct cache_def *cache,
|
||||||
* can still cache the path components before the last
|
* can still cache the path components before the last
|
||||||
* one (the found symlink or non-existing component).
|
* one (the found symlink or non-existing component).
|
||||||
*/
|
*/
|
||||||
cache->path[last_slash_dir] = '\0';
|
cache->path.buf[last_slash_dir] = '\0';
|
||||||
cache->len = last_slash_dir;
|
cache->path.len = last_slash_dir;
|
||||||
cache->flags = FL_DIR;
|
cache->flags = FL_DIR;
|
||||||
} else {
|
} else {
|
||||||
reset_lstat_cache(cache);
|
reset_lstat_cache(cache);
|
||||||
|
@ -273,21 +272,18 @@ static int threaded_has_dirs_only_path(struct cache_def *cache, const char *name
|
||||||
FL_DIR;
|
FL_DIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct removal_def {
|
static struct strbuf removal = STRBUF_INIT;
|
||||||
char path[PATH_MAX];
|
|
||||||
int len;
|
|
||||||
} removal;
|
|
||||||
|
|
||||||
static void do_remove_scheduled_dirs(int new_len)
|
static void do_remove_scheduled_dirs(int new_len)
|
||||||
{
|
{
|
||||||
while (removal.len > new_len) {
|
while (removal.len > new_len) {
|
||||||
removal.path[removal.len] = '\0';
|
removal.buf[removal.len] = '\0';
|
||||||
if (rmdir(removal.path))
|
if (rmdir(removal.buf))
|
||||||
break;
|
break;
|
||||||
do {
|
do {
|
||||||
removal.len--;
|
removal.len--;
|
||||||
} while (removal.len > new_len &&
|
} while (removal.len > new_len &&
|
||||||
removal.path[removal.len] != '/');
|
removal.buf[removal.len] != '/');
|
||||||
}
|
}
|
||||||
removal.len = new_len;
|
removal.len = new_len;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +293,7 @@ void schedule_dir_for_removal(const char *name, int len)
|
||||||
int match_len, last_slash, i, previous_slash;
|
int match_len, last_slash, i, previous_slash;
|
||||||
|
|
||||||
match_len = last_slash = i =
|
match_len = last_slash = i =
|
||||||
longest_path_match(name, len, removal.path, removal.len,
|
longest_path_match(name, len, removal.buf, removal.len,
|
||||||
&previous_slash);
|
&previous_slash);
|
||||||
/* Find last slash inside 'name' */
|
/* Find last slash inside 'name' */
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
|
@ -317,11 +313,8 @@ void schedule_dir_for_removal(const char *name, int len)
|
||||||
* If we go deeper down the directory tree, we only need to
|
* If we go deeper down the directory tree, we only need to
|
||||||
* save the new path components as we go down.
|
* save the new path components as we go down.
|
||||||
*/
|
*/
|
||||||
if (match_len < last_slash) {
|
if (match_len < last_slash)
|
||||||
memcpy(&removal.path[match_len], &name[match_len],
|
strbuf_add(&removal, &name[match_len], last_slash - match_len);
|
||||||
last_slash - match_len);
|
|
||||||
removal.len = last_slash;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_scheduled_dirs(void)
|
void remove_scheduled_dirs(void)
|
||||||
|
|
Loading…
Reference in New Issue