Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive/tar: FileInfoHeader cannot parse Windows directory symlinks #17541

Closed
jim-minter opened this issue Oct 21, 2016 · 3 comments
Closed

archive/tar: FileInfoHeader cannot parse Windows directory symlinks #17541

jim-minter opened this issue Oct 21, 2016 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@jim-minter
Copy link

On Windows, a symlink to a directory is reported as a directory and a symlink at the same time. This confuses tar.FileInfoHeader, which reports the object as a directory, whereas on UNIX systems it would be reported as a symlink. I believe it makes much more sense to report a symlink.

What version of Go are you using (go version)?

$ go version
go version go1.7.1 windows/amd64

What operating system and processor architecture are you using (go env)?

$ go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=x:\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

What did you do?

Run the following program:

package main

import (
    "archive/tar"
    "fmt"
    "io/ioutil"
    "os"
    "path/filepath"
)

func main() {
    tempdir, err := ioutil.TempDir("", "")
    if err != nil {
        panic(err)
    }
    defer os.RemoveAll(tempdir)

    os.Symlink(`c:\`, filepath.Join(tempdir, "directorysymlink"))
    // os.Symlink("/", filepath.Join(tempdir, "directorysymlink"))

    fi, err := os.Lstat(filepath.Join(tempdir, "directorysymlink"))
    if err != nil {
        panic(err)
    }
    hdr, err := tar.FileInfoHeader(fi, "directorysymlink")
    if err != nil {
        panic(err)
    }

    fmt.Printf("Typeflag: %c, Mode: 0x%x, Linkname: %q\n", hdr.Typeflag, hdr.Mode, hdr.Linkname)
}

What did you expect to see?

On Windows, this returns Typeflag: 5, Mode: 0x41ff, Linkname: ""

What did you see instead?

I'd expect to see Typeflag: 2, Mode: 0xa1ff, Linkname: "directorysymlink", as is reported on non-Windows systems.

@quentinmit quentinmit changed the title On Windows tar.FileInfoHeader reports directory symlinks as a directory, not a symlink archive/tar: FileInfoHeader cannot parse Windows directory symlinks Oct 21, 2016
@quentinmit quentinmit added OS-Windows NeedsFix The path to resolution is known, but the work has not been done. labels Oct 21, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Oct 21, 2016
@dsnet
Copy link
Member

dsnet commented Oct 21, 2016

I have a windows machine. I can look into this.

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Apr 25, 2017
For #17541.

Change-Id: I524ab194f32b8b061ce1c9c3e0cd34cc5539358e
Reviewed-on: https://go-review.googlesource.com/39410
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@gopherbot
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

4 participants