-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #73 by normalizing paths to UNC on windows. This is _slightly_ less hacky than registering a new schema. The underlying issue was twofold: 1. When specifying a windows file URL as `file://c:/foo/bar`, go barfs because `:` can't be in a domain name. 2. When specifying a windows file URL as `file:///c:/foo/bar`, we'd end up trying to open `/c:/foo/bar` which is actually `CURRENT_DRIVE:/c:/foo/bar`.
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//+build !windows | ||
|
||
package log | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
func normalizePath(p string) (string, error) { | ||
return filepath.Abs(p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//+build windows | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func normalizePath(p string) (string, error) { | ||
if p == "" { | ||
return "", fmt.Errorf("path empty") | ||
} | ||
p, err := filepath.Abs(p) | ||
if err != nil { | ||
return "", err | ||
} | ||
// Is this _really_ an absolute path? | ||
if !strings.HasPrefix(p, "\\\\") { | ||
// It's a drive: path! | ||
// Return a UNC path. | ||
p = "\\\\?\\" + p | ||
} | ||
|
||
// This will return file:////?/c:/foobar | ||
// | ||
// Why? Because: | ||
// 1. Go will choke on file://c:/ because the "domain" includes a :. | ||
// 2. Windows will choke on file:///c:/ because the path will be | ||
// /c:/... which is _relative_ to the current drive. | ||
// | ||
// This path (a) has no "domain" and (b) starts with a slash. Yay! | ||
return "file://" + filepath.ToSlash(p), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters