Skip to content

Commit

Permalink
fix win32 UNC path handling (#183)
Browse files Browse the repository at this point in the history
* Don't normalize UNC prefix

* Don't try to add unc prefix for path with unc prefix

* Properly change forward slashes to backward slashes in Win32 MakePlatformPath

* release notes
  • Loading branch information
DanEngelbrecht authored Feb 25, 2022
1 parent 9bd8457 commit de810e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ jobs:
release_name: Release ${{ env.RELEASE_VERSION }}
body: |
# Changes in this Release
- **CHANGED API** Added `GetParentPath()` to `Storage_API`
- **FIX** EnsureParentPath now handles Windows path with backslashes properly
- **FIX** Properly handle UNC paths
draft: false
prerelease: false
files: "*-x64.zip"
4 changes: 4 additions & 0 deletions cmd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ static char* NormalizePath(const char* path)
char* normalized_path = Longtail_Strdup(path);
size_t wi = 0;
size_t ri = 0;
if (normalized_path[0] == '\\' && normalized_path[1] == '\\' && normalized_path[2] == '?' && normalized_path[3] == '\\')
{
ri += 4;
}
while (path[ri])
{
switch (path[ri])
Expand Down
7 changes: 6 additions & 1 deletion lib/longtail_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ static const wchar_t* MakeLongPath(const wchar_t* path)
// Don't add long path prefix if we don't specify a drive
return path;
}
if (path[0] == '\\' && path[1] == '\\' && path[2] == '?' && path[3] == '\\')
{
// Don't add long path prefix if we aleady have an UNC path
return path;
}
size_t path_len = wcslen(path);
if (path_len < MAX_PATH)
{
Expand Down Expand Up @@ -374,7 +379,7 @@ static wchar_t* MakePlatformPath(const char* path)
wchar_t* p = r;
while (*p)
{
*r = ((*r) == '/') ? '\\' : (*r);
*p = ((*p) == '/') ? '\\' : (*p);
++p;
}
return r;
Expand Down

0 comments on commit de810e0

Please sign in to comment.