This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 578
Invalid case-insensitive filepath handling #982
Milestone
Comments
A PR would be very welcome!
…-----------
Mark Bates
On Mar 22, 2018, 6:21 AM -0400, Egon Elbre ***@***.***>, wrote:
Some FileSystems are case-insensitive, mainly Windows, which means using strings.TrimPrefix to find the relative directory or path, will eventually fail. Something like this, will be probably more successful in most cases:
func ImportPath(gopaths []string, targetpath string) (string, error) {
var err error
var rel string
for _, gopath := range gopaths {
rel, err = filepath.Rel(gopath, targetpath)
if err == nil {
return filpath.ToSlash(rel), nil
}
}
return nil, err
}
Example in Windows with a case-mismatch:
f:\Go\src\sandbox\buffalo>echo %GOPATH%
F:\Go
f:\Go\src\sandbox\buffalo>buffalo new example
create .buffalo.dev.yml
create assets/images/logo.svg
create assets\css\application.scss
<<< SNIP >>>
create public\robots.txt
create templates\_flash.html
create templates\application.html
create templates\index.html
run go get -t ./...
can't load package: package sandbox/buffalo/example:
main.go:6:3: invalid import path: "f:/Go/src/sandbox/buffalo/example/actions"
can't load package: package sandbox/buffalo/example/actions:
actions\app.go:11:3: invalid import path: "f:/Go/src/sandbox/buffalo/example/models"
can't load package: package sandbox/buffalo/example/grifts:
grifts\init.go:5:2: invalid import path: "f:/Go/src/sandbox/buffalo/example/actions"
Usage:
buffalo new [name] [flags]
<<< SNIP >>>
ERRO[0038] Error: exit status 1
And the main.go, app.go, Dockerfile... contain import paths such as:
package main
import (
"log"
"f:/Go/src/sandbox/buffalo/example/actions"
)
func main() {
app := actions.App()
if err := app.Serve(); err != nil {
log.Fatal(err)
}
}
I suspect there are other places that may contain similar mistakes.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Tried my best. I wasn't sure what the policy of error handling is, but I took the following approach:
I'm not sure what the appropriate action should be for paths that are outside of GoPath, or is that handled somewhere further above? In those cases the result from |
PS: I'm not sure whether I caught them all. There were few strings.TrimPrefix-es that I wasn't sure about, and there might be some dependencies outside of gobuffalo that are still affected. |
Also there might be a better place to put that version of |
markbates
pushed a commit
to gobuffalo/envy
that referenced
this issue
Mar 25, 2018
strings.TrimPrefix can give the wrong result with case-insensitive paths. filepath.Rel usually works better.
markbates
pushed a commit
to gobuffalo/packr
that referenced
this issue
Mar 25, 2018
strings.TrimPrefix can give the wrong result with case-insensitive paths. filepath.Rel usually works better.
markbates
pushed a commit
that referenced
this issue
Mar 25, 2018
Thank you for this! |
stanislas-m
pushed a commit
that referenced
this issue
May 12, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Some FileSystems are case-insensitive, mainly Windows, which means using
strings.TrimPrefix
to find the relative directory or path, will eventually fail. Something like this, will be probably more successful in most cases:Example in Windows with a case-mismatch:
And the main.go, app.go, Dockerfile... contain import paths such as:
I suspect there are other places that may contain similar mistakes.
The text was updated successfully, but these errors were encountered: