Merge pull request #240 from jasonberanek/windows-paths-fix
common: Fix URL and Relative Windows file path support #235/#239
This commit is contained in:
commit
a1668a73dc
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -73,6 +74,12 @@ func DownloadableURL(original string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if url.Scheme == "file" {
|
if url.Scheme == "file" {
|
||||||
|
// For Windows absolute file paths, remove leading /
|
||||||
|
// prior to processing
|
||||||
|
if runtime.GOOS == "windows" && url.Path[0] == '/' {
|
||||||
|
url.Path = url.Path[1:len(url.Path)]
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(url.Path); err != nil {
|
if _, err := os.Stat(url.Path); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DownloadConfig is the configuration given to instantiate a new
|
// DownloadConfig is the configuration given to instantiate a new
|
||||||
|
@ -106,7 +107,13 @@ func (d *DownloadClient) Get() (string, error) {
|
||||||
// Files when we don't copy the file are special cased.
|
// Files when we don't copy the file are special cased.
|
||||||
var finalPath string
|
var finalPath string
|
||||||
if url.Scheme == "file" && !d.config.CopyFile {
|
if url.Scheme == "file" && !d.config.CopyFile {
|
||||||
finalPath = url.Path
|
// Remove forward slash on absolute Windows file URLs
|
||||||
|
// Before processing
|
||||||
|
if runtime.GOOS == "windows" && url.Path[0] == '/' {
|
||||||
|
finalPath = url.Path[1:len(url.Path)]
|
||||||
|
} else {
|
||||||
|
finalPath = url.Path
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
finalPath = d.config.TargetPath
|
finalPath = d.config.TargetPath
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue