Skip to content

Commit 713194c

Browse files
committed
Merge branch 'jh/threadable-symlink-check'
By Jared Hance * jh/threadable-symlink-check: Add threaded versions of functions in symlinks.c.
2 parents 239d6ed + 15438d5 commit 713194c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,9 @@ struct cache_def {
950950
extern int has_symlink_leading_path(const char *name, int len);
951951
extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
952952
extern int check_leading_path(const char *name, int len);
953+
extern int threaded_check_leading_path(struct cache_def *cache, const char *name, int len);
953954
extern int has_dirs_only_path(const char *name, int len, int prefix_len);
955+
extern int threaded_has_dirs_only_path(struct cache_def *cache, const char *name, int len, int prefix_len);
954956
extern void schedule_dir_for_removal(const char *name, int len);
955957
extern void remove_scheduled_dirs(void);
956958

symlinks.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,20 @@ int has_symlink_leading_path(const char *name, int len)
219219
*/
220220
int check_leading_path(const char *name, int len)
221221
{
222-
struct cache_def *cache = &default_cache; /* FIXME */
222+
return threaded_check_leading_path(&default_cache, name, len);
223+
}
224+
225+
/*
226+
* Return zero if path 'name' has a leading symlink component or
227+
* if some leading path component does not exists.
228+
*
229+
* Return -1 if leading path exists and is a directory.
230+
*
231+
* Return path length if leading path exists and is neither a
232+
* directory nor a symlink.
233+
*/
234+
int threaded_check_leading_path(struct cache_def *cache, const char *name, int len)
235+
{
223236
int flags;
224237
int match_len = lstat_cache_matchlen(cache, name, len, &flags,
225238
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT);
@@ -240,7 +253,18 @@ int check_leading_path(const char *name, int len)
240253
*/
241254
int has_dirs_only_path(const char *name, int len, int prefix_len)
242255
{
243-
struct cache_def *cache = &default_cache; /* FIXME */
256+
return threaded_has_dirs_only_path(&default_cache, name, len, prefix_len);
257+
}
258+
259+
/*
260+
* Return non-zero if all path components of 'name' exists as a
261+
* directory. If prefix_len > 0, we will test with the stat()
262+
* function instead of the lstat() function for a prefix length of
263+
* 'prefix_len', thus we then allow for symlinks in the prefix part as
264+
* long as those points to real existing directories.
265+
*/
266+
int threaded_has_dirs_only_path(struct cache_def *cache, const char *name, int len, int prefix_len)
267+
{
244268
return lstat_cache(cache, name, len,
245269
FL_DIR|FL_FULLPATH, prefix_len) &
246270
FL_DIR;

0 commit comments

Comments
 (0)