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: incorrect file extension #48290

Closed
dataflowjs opened this issue Sep 9, 2021 · 2 comments
Closed

archive/tar: incorrect file extension #48290

dataflowjs opened this issue Sep 9, 2021 · 2 comments

Comments

@dataflowjs
Copy link

dataflowjs commented Sep 9, 2021

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

$ go version
1.17

Does this issue reproduce with the latest release?

duno

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

Windows 10 64 bit

go env Output
$ go env

What did you do?

Hi! I have a list of *.yml files, im archive this files to one tar file, but one or two of them after process have different extension after tar is done, why?

What did you expect to see?

.yml extension

What did you see instead?

.yml0000777 extension

package main

import (
	"archive/tar"
	"io/ioutil"
	"log"
	"os"
)

func main() {
	// Create and add some files to the archive.
	f, err := os.Create("test.tar")
	if err != nil {
		panic(err)
	}
	defer f.Close()

	tw := tar.NewWriter(f)
	defer tw.Close()

	file, err := os.Open("puma_Она_Обувь_Кроссовки, сникеры_На каждый день (Lifestyle).yml")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	fileInfo, err := file.Stat()
	if err != nil {
		log.Println(err)
	}

	hdr := &tar.Header{
		Name:   file.Name(),
		Mode:   0777,
		Size:   fileInfo.Size(),
		Format: tar.FormatGNU,
	}

	if err := tw.WriteHeader(hdr); err != nil {
		log.Fatal(err)
	}

	bin, err := ioutil.ReadAll(file)
	if err != nil {
		log.Println(err)
	}

	if _, err := tw.Write(bin); err != nil {
		log.Fatal(err)
	}

	if err := tw.Close(); err != nil {
		log.Fatal(err)
	}
}

the code with .yml (xml) file im trying to tar without change its extension
tartest.zip

1

@dsnet
Copy link
Member

dsnet commented Sep 9, 2021

This does not seem to be an issue with Go's implementation of TAR. Using GNU tar v1.30 and bsdtar v3.4.0, both are able to parse a TAR archive produced by Go v1.17 with the correct filename. Rather, it seems to be an issue with the program trying to read this.

@dsnet dsnet changed the title tar package changes file extension archive/tar: incorrect file extension Sep 9, 2021
@seankhliao
Copy link
Member

Closing as not a bug in Go

@golang golang locked and limited conversation to collaborators Sep 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants