Skip to content

Commit b846434

Browse files
committed
path: rename function that detects end of filename
The function `only_spaces_and_dots` used to detect the end of the filename on win32. Now we look at spaces and dots _before_ the end of the string _or_ a `:` character, which would signify a win32 alternate data stream. Thus, rename the function `ntfs_end_of_filename` to indicate that it detects the (virtual) end of a filename, that any further characters would be elided to the given path.
1 parent e1832eb commit b846434

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/path.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,16 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size
16411641
return false;
16421642
}
16431643

1644-
GIT_INLINE(bool) only_spaces_and_dots(const char *path)
1644+
/*
1645+
* Windows paths that end with spaces and/or dots are elided to the
1646+
* path without them for backward compatibility. That is to say
1647+
* that opening file "foo ", "foo." or even "foo . . ." will all
1648+
* map to a filename of "foo". This function identifies spaces and
1649+
* dots at the end of a filename, whether the proper end of the
1650+
* filename (end of string) or a colon (which would indicate a
1651+
* Windows alternate data stream.)
1652+
*/
1653+
GIT_INLINE(bool) ntfs_end_of_filename(const char *path)
16451654
{
16461655
const char *c = path;
16471656

@@ -1661,13 +1670,13 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const
16611670

16621671
if (name[0] == '.' && len >= dotgit_len &&
16631672
!strncasecmp(name + 1, dotgit_name, dotgit_len)) {
1664-
return !only_spaces_and_dots(name + dotgit_len + 1);
1673+
return !ntfs_end_of_filename(name + dotgit_len + 1);
16651674
}
16661675

16671676
/* Detect the basic NTFS shortname with the first six chars */
16681677
if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' &&
16691678
name[7] >= '1' && name[7] <= '4')
1670-
return !only_spaces_and_dots(name + 8);
1679+
return !ntfs_end_of_filename(name + 8);
16711680

16721681
/* Catch fallback names */
16731682
for (i = 0, saw_tilde = 0; i < 8; i++) {
@@ -1689,7 +1698,7 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const
16891698
}
16901699
}
16911700

1692-
return !only_spaces_and_dots(name + i);
1701+
return !ntfs_end_of_filename(name + i);
16931702
}
16941703

16951704
GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags)

0 commit comments

Comments
 (0)