mirror of
https://github.com/git/git.git
synced 2026-03-13 10:23:30 +01:00
Accept trailing slashes in lstat() implementation.
lstat() is sometimes invoked with a path that ends in a slash (in particular, when dealing with subprojects). Windows's stat() does not accept such paths and fails with ENOENT. In this case we try again with a cleaned-up path.
This commit is contained in:
@@ -25,7 +25,27 @@ int fchmod(int fildes, mode_t mode)
|
||||
|
||||
int lstat(const char *file_name, struct stat *buf)
|
||||
{
|
||||
return stat(file_name, buf);
|
||||
int namelen;
|
||||
static char alt_name[PATH_MAX];
|
||||
|
||||
if (!stat(file_name, buf))
|
||||
return 0;
|
||||
|
||||
/* if file_name ended in a '/', Windows returned ENOENT;
|
||||
* try again without trailing slashes
|
||||
*/
|
||||
if (errno != ENOENT)
|
||||
return -1;
|
||||
namelen = strlen(file_name);
|
||||
if (namelen && file_name[namelen-1] != '/')
|
||||
return -1;
|
||||
while (namelen && file_name[namelen-1] == '/')
|
||||
--namelen;
|
||||
if (!namelen || namelen >= PATH_MAX)
|
||||
return -1;
|
||||
memcpy(alt_name, file_name, namelen);
|
||||
alt_name[namelen] = 0;
|
||||
return stat(alt_name, buf);
|
||||
}
|
||||
|
||||
/* missing: link, mkstemp, fchmod, getuid (?), gettimeofday */
|
||||
|
||||
Reference in New Issue
Block a user