From 760f102c91c3befe0eb571caef18b2048b8d25ff Mon Sep 17 00:00:00 2001 From: "Jason A. Beranek" Date: Fri, 2 Aug 2013 15:59:19 -0500 Subject: [PATCH 1/2] common/config,download: fix URL and relative Windows local file path issues [GH-235] [GH-239] --- common/config.go | 7 +++++++ common/download.go | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/config.go b/common/config.go index 94b03e2b1..12c53cc25 100644 --- a/common/config.go +++ b/common/config.go @@ -7,6 +7,7 @@ import ( "net/url" "os" "path/filepath" + "runtime" "sort" "strings" ) @@ -73,6 +74,12 @@ func DownloadableURL(original string) (string, error) { } 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 { return "", err } diff --git a/common/download.go b/common/download.go index eaf2f22d5..4e93b37ec 100644 --- a/common/download.go +++ b/common/download.go @@ -14,6 +14,7 @@ import ( "net/http" "net/url" "os" + "runtime" ) // 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. var finalPath string 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 { finalPath = d.config.TargetPath From 3fa5fa396a0f1a7fd514927ccf793b0d4f7d15f9 Mon Sep 17 00:00:00 2001 From: "Jason A. Beranek" Date: Fri, 2 Aug 2013 16:06:06 -0500 Subject: [PATCH 2/2] common/config,download: gofmt fixes --- common/config.go | 12 ++++++------ common/download.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common/config.go b/common/config.go index 12c53cc25..3ea041a6f 100644 --- a/common/config.go +++ b/common/config.go @@ -7,7 +7,7 @@ import ( "net/url" "os" "path/filepath" - "runtime" + "runtime" "sort" "strings" ) @@ -74,11 +74,11 @@ func DownloadableURL(original string) (string, error) { } 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)] - } + // 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 { return "", err diff --git a/common/download.go b/common/download.go index 4e93b37ec..0997b0f1d 100644 --- a/common/download.go +++ b/common/download.go @@ -14,7 +14,7 @@ import ( "net/http" "net/url" "os" - "runtime" + "runtime" ) // DownloadConfig is the configuration given to instantiate a new @@ -107,13 +107,13 @@ func (d *DownloadClient) Get() (string, error) { // Files when we don't copy the file are special cased. var finalPath string if url.Scheme == "file" && !d.config.CopyFile { - // Remove forward slash on absolute Windows file URLs - // Before processing + // 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 - } + finalPath = url.Path[1:len(url.Path)] + } else { + finalPath = url.Path + } } else { finalPath = d.config.TargetPath