Replace Mutex name hashing with URI escaping (Fix #2543) #2557
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.
Shared
mode uses a named Mutex to avoid multiple processes reading/writing at the same time. LiteDB names the Mutex to contain the absolute file path of the database. But Mutex names have to be valid file paths, so this would cause an invalid file path like:So instead, currently it hashes the file path using SHA1 to turn it into the following:
However, this is a hacky solution in my opinion. Someone experienced exceptions (#2543) caused when creating SHA1. This PR avoids the need to hash the path by using URL escaping:
Also, I changed it to use
.ToLowerInvariant()
instead of.ToLower()
because Windows file paths are case insensitive even for non-ASCII characters (e.g.É
andé
).This PR should fix #2543 since it removes hashing.