pack: escape characters before using them in glob patterns #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we open a pack file, we use a glob pattern to find the pack files that are in our pack directory and then attempt to open them. This works fine if our directory contains no characters that are special to the shell, but works poorly when we handle characters that are special in glob patterns, most notably the left square bracket. In such a case, our pattern doesn't actually match anything, so we don't open any pack files. Git LFS then complains about a missing object.
Escape all the characters which are special to the shell so that we can handle these paths properly. Use character classes instead of backslashes because backslash escaping is not available on Windows. For the same reason, punt on handling backslashes on Unix systems because there isn't a great way to handle them portably.