Closed
Description
% go version
go version go1.7 linux/amd64
% go env
GOARCH="amd64"
GOBIN="/home/cyphar/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/cyphar/.local"
GORACE=""
GOROOT="/usr/lib64/go"
GOTOOLDIR="/usr/lib64/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build013320516=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
This also happens on https://play.golang.org/, which you can see in this snippet: https://play.golang.org/p/QURChe1JI_.
package main
import (
"archive/tar"
"fmt"
"io"
"time"
)
func main() {
reader, writer := io.Pipe()
atime := time.Unix(123, 0)
mtime := time.Unix(777, 0)
ctime := time.Unix(1337, 0)
tw := tar.NewWriter(writer)
tr := tar.NewReader(reader)
go func() {
tw.WriteHeader(&tar.Header{
Name: "somefile",
Mode: 0777,
ModTime: mtime,
AccessTime: atime,
ChangeTime: ctime,
})
tw.Close()
}()
hdr, err := tr.Next()
if err != nil {
panic(err)
}
if !hdr.ModTime.Equal(mtime) {
fmt.Printf("mtime not equal! got %s, expected %s\n", hdr.ModTime, mtime)
}
if !hdr.AccessTime.Equal(atime) {
fmt.Printf("atime not equal! got %s, expected %s\n", hdr.AccessTime, atime)
}
if !hdr.ChangeTime.Equal(ctime) {
fmt.Printf("ctime not equal! got %s, expected %s\n", hdr.ChangeTime, ctime)
}
}
What did you expect to see?
No errors in the above program.
What did you see instead?
% go run broken.go
atime not equal! got 0001-01-01 00:00:00 +0000 UTC, expected 1970-01-01 10:02:03 +1000 AEST
ctime not equal! got 0001-01-01 00:00:00 +0000 UTC, expected 1970-01-01 10:22:17 +1000 AEST
From what I can tell, this is caused by the fact that WriteHeader
doesn't in any way touch the AccessTime
of the structure. The same goes for the ChangeTime
.