1
1
#include "cache.h"
2
2
3
- static int threaded_check_leading_path (struct cache_def * cache , const char * name , int len );
3
+ static int threaded_check_leading_path (struct cache_def * cache , const char * name ,
4
+ int len , int warn_on_lstat_err );
4
5
static int threaded_has_dirs_only_path (struct cache_def * cache , const char * name , int len , int prefix_len );
5
6
6
7
/*
@@ -72,7 +73,7 @@ static int lstat_cache_matchlen(struct cache_def *cache,
72
73
int prefix_len_stat_func )
73
74
{
74
75
int match_len , last_slash , last_slash_dir , previous_slash ;
75
- int save_flags , ret ;
76
+ int save_flags , ret , saved_errno = 0 ;
76
77
struct stat st ;
77
78
78
79
if (cache -> track_flags != track_flags ||
@@ -139,6 +140,7 @@ static int lstat_cache_matchlen(struct cache_def *cache,
139
140
140
141
if (ret ) {
141
142
* ret_flags = FL_LSTATERR ;
143
+ saved_errno = errno ;
142
144
if (errno == ENOENT )
143
145
* ret_flags |= FL_NOENT ;
144
146
} else if (S_ISDIR (st .st_mode )) {
@@ -180,6 +182,8 @@ static int lstat_cache_matchlen(struct cache_def *cache,
180
182
} else {
181
183
reset_lstat_cache (cache );
182
184
}
185
+ if (saved_errno )
186
+ errno = saved_errno ;
183
187
return match_len ;
184
188
}
185
189
@@ -202,57 +206,47 @@ int threaded_has_symlink_leading_path(struct cache_def *cache, const char *name,
202
206
return lstat_cache (cache , name , len , FL_SYMLINK |FL_DIR , USE_ONLY_LSTAT ) & FL_SYMLINK ;
203
207
}
204
208
205
- /*
206
- * Return non-zero if path 'name' has a leading symlink component
207
- */
208
209
int has_symlink_leading_path (const char * name , int len )
209
210
{
210
211
return threaded_has_symlink_leading_path (& default_cache , name , len );
211
212
}
212
213
213
- /*
214
- * Return zero if path 'name' has a leading symlink component or
215
- * if some leading path component does not exists.
216
- *
217
- * Return -1 if leading path exists and is a directory.
218
- *
219
- * Return path length if leading path exists and is neither a
220
- * directory nor a symlink.
221
- */
222
- int check_leading_path (const char * name , int len )
214
+ int check_leading_path (const char * name , int len , int warn_on_lstat_err )
223
215
{
224
- return threaded_check_leading_path (& default_cache , name , len );
216
+ return threaded_check_leading_path (& default_cache , name , len ,
217
+ warn_on_lstat_err );
225
218
}
226
219
227
220
/*
228
- * Return zero if path 'name' has a leading symlink component or
229
- * if some leading path component does not exists.
221
+ * Return zero if some leading path component of 'name' does not exist.
230
222
*
231
223
* Return -1 if leading path exists and is a directory.
232
224
*
233
- * Return path length if leading path exists and is neither a
234
- * directory nor a symlink.
225
+ * Return the length of a leading component if it either exists but it's not a
226
+ * directory, or if we were unable to lstat() it. If warn_on_lstat_err is true,
227
+ * also emit a warning for this error.
235
228
*/
236
- static int threaded_check_leading_path (struct cache_def * cache , const char * name , int len )
229
+ static int threaded_check_leading_path (struct cache_def * cache , const char * name ,
230
+ int len , int warn_on_lstat_err )
237
231
{
238
232
int flags ;
239
233
int match_len = lstat_cache_matchlen (cache , name , len , & flags ,
240
234
FL_SYMLINK |FL_NOENT |FL_DIR , USE_ONLY_LSTAT );
235
+ int saved_errno = errno ;
236
+
241
237
if (flags & FL_NOENT )
242
238
return 0 ;
243
239
else if (flags & FL_DIR )
244
240
return -1 ;
245
- else
246
- return match_len ;
241
+ if (warn_on_lstat_err && (flags & FL_LSTATERR )) {
242
+ char * path = xmemdupz (name , match_len );
243
+ errno = saved_errno ;
244
+ warning_errno (_ ("failed to lstat '%s'" ), path );
245
+ free (path );
246
+ }
247
+ return match_len ;
247
248
}
248
249
249
- /*
250
- * Return non-zero if all path components of 'name' exists as a
251
- * directory. If prefix_len > 0, we will test with the stat()
252
- * function instead of the lstat() function for a prefix length of
253
- * 'prefix_len', thus we then allow for symlinks in the prefix part as
254
- * long as those points to real existing directories.
255
- */
256
250
int has_dirs_only_path (const char * name , int len , int prefix_len )
257
251
{
258
252
return threaded_has_dirs_only_path (& default_cache , name , len , prefix_len );
0 commit comments