diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2019-12-03 17:47:31 +1100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-12-10 11:04:48 +0100 |
commit | f49378b6f1ee639a3bfb843a18db5adac7fde9df (patch) | |
tree | 4d000ed50de280850c132c14f00b015c133f6017 | |
parent | ac0b2ef1f50fb961a990638520f3b09d06bc2141 (diff) | |
download | libgit2-f49378b6f1ee639a3bfb843a18db5adac7fde9df.tar.gz |
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.
-rw-r--r-- | src/path.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/path.c b/src/path.c index fcc1bd28d..53886ad86 100644 --- a/src/path.c +++ b/src/path.c @@ -1626,7 +1626,16 @@ GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size return false; } -GIT_INLINE(bool) only_spaces_and_dots(const char *path) +/* + * Windows paths that end with spaces and/or dots are elided to the + * path without them for backward compatibility. That is to say + * that opening file "foo ", "foo." or even "foo . . ." will all + * map to a filename of "foo". This function identifies spaces and + * dots at the end of a filename, whether the proper end of the + * filename (end of string) or a colon (which would indicate a + * Windows alternate data stream.) + */ +GIT_INLINE(bool) ntfs_end_of_filename(const char *path) { const char *c = path; @@ -1646,13 +1655,13 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const if (name[0] == '.' && len >= dotgit_len && !strncasecmp(name + 1, dotgit_name, dotgit_len)) { - return !only_spaces_and_dots(name + dotgit_len + 1); + return !ntfs_end_of_filename(name + dotgit_len + 1); } /* Detect the basic NTFS shortname with the first six chars */ if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' && name[7] >= '1' && name[7] <= '4') - return !only_spaces_and_dots(name + 8); + return !ntfs_end_of_filename(name + 8); /* Catch fallback names */ for (i = 0, saw_tilde = 0; i < 8; i++) { @@ -1674,7 +1683,7 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const } } - return !only_spaces_and_dots(name + i); + return !ntfs_end_of_filename(name + i); } GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags) |