Go: path/filepath: EvalSymlinks is broken for relative paths on Windows

Created on 18 Aug 2016  路  14Comments  路  Source: golang/go

This seems to have been introduced with the rework on filepath.EvalSymlinks from this issue: #13980 on this commit: c4dda7e5a830e86b597d34483fd7787723b34f2f

  1. What version of Go are you using (go version)?
    go version go1.7 windows/amd64
  2. What operating system and processor architecture are you using (go env)?
    windows/amd64
  3. What did you do?

The following code reproduces the problem:

package main

import (
    "fmt"
    "os"
    "path/filepath"
)

func main() {
    path := filepath.Join("..", "..", "foo")
    err := os.MkdirAll(path, 0644)
    if err != nil {
        panic(err)
    }

    evaldPath, err := filepath.EvalSymlinks(path)
    if err != nil {
        panic(err)
    }

    absPath, err := filepath.Abs(evaldPath)
    if err != nil {
        panic(err)
    }

    expectedPath, err := filepath.Abs(path)
    if err != nil {
        panic(err)
    }

    fmt.Printf("original path: %s\n", path)
    fmt.Printf("eval'd path: %s\n", absPath)
    fmt.Printf("expected path: %s\n", expectedPath)
}
  1. What did you expect to see?
> go run main.go
original path: ../../foo
eval'd path: C:\gopath\foo
expected path: C:\gopath\foo

  1. What did you see instead?
> go run main.go
original path: ..\..\foo
eval'd path: C:\gopath\src\pathtest\src\gopath\foo
expected path: C:\gopath\foo
FrozenDueToAge

Most helpful comment

@hirochachacha, don't worry about it. We break things all the time. It happens.

All 14 comments

Oh... I've confirmed. Thank you.

CL https://golang.org/cl/27410 mentions this issue.

FWIW, it doesn't exist before 1.7.
Maybe this is 1.7.1 worthy.

I'd be great if this makes into 1.7.1 since it's a bug introduced on 1.7 and is preventing us from cleanly upgrading to 1.7. And we really really want to upgrade!

/cc @ianlancetaylor @adg @broady on 1.7.1 thoughts.

That looks very broken. How did this break?

Because of my fault. I didn't expect this case. I'm really sorry.

@hirochachacha, don't worry about it. We break things all the time. It happens.

thanks.

I'm probably OK with a fix for this going into 1.7.1 but as far as I can tell it has not been fixed on tip yet. The CL attached to this issue has not been submitted, and doesn't have any tests.

@hirochachacha can you link to the CL that caused this?

Oh, sorry. https://go-review.googlesource.com/#/c/20860/ is original one. (above one is test for this)

@hirochachacha please include the fix and new tests in the same CL and have that CL reference this bug ("Fixes #16793")

Was this page helpful?
0 / 5 - 0 ratings