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

ArchiveFS stat and using section reader #334

Closed
WeidiDeng opened this issue Apr 20, 2022 · 3 comments · Fixed by #335
Closed

ArchiveFS stat and using section reader #334

WeidiDeng opened this issue Apr 20, 2022 · 3 comments · Fixed by #335

Comments

@WeidiDeng
Copy link
Contributor

What version of the package or command are you using?

v4.0.0-alpha.6

What are you trying to do?

Because golang embed doesn't compress fs, I precompressed the file and embed it to a string, and use that string as section reader to use as fs.FS. Because other parts of the program use archiver, I want to use it here as well.

What steps did you take?

assets.tar.gz

package main

import (
	_ "embed"
	"github.com/mholt/archiver/v4"
	"io"
	"io/fs"
	"log"
	"strings"
)

var (
	//go:embed assets.tar.gz
	s string
	F fs.FS
)

func init() {
	reader := strings.NewReader(s)
	format, _, _ := archiver.Identify("", reader)
	F = archiver.ArchiveFS{
		Stream: io.NewSectionReader(reader, 0, reader.Size()),
		Format: format.(archiver.Archival),
		Prefix: "",
	}
	//F, _ = archiver.FileSystem("assets.tar.gz") // actually return an ArchiveFS
}

func main() {
	log.Println(F.Open("assets"))
	log.Println(F.Open("."))
	log.Println(fs.Stat(F, "assets"))
	log.Println(fs.Stat(F, "."))
	_ = fs.WalkDir(F, "assets", func(path string, d fs.DirEntry, err error) error {
		log.Println(path, d, err)
		return err
	})
}

What did you expect to happen, and what actually happened instead?

Expected: All calls return no error.

Actual: SectionReader Variant: open(".") fail, all stat call fail. File path variant, all stat except "." return file doesn't exist error. Even though when the path is successfully opened, the returned file stat method return successfully.

How do you think this should be fixed?

SectionReader should behave the same as specifying the path. And path variant should allow stat path other than ".".

Please link to any related issues, pull requests, and/or discussion

Bonus: What do you use archiver for, and do you find it useful?

@WeidiDeng
Copy link
Contributor Author

Strangely, if I use fs.Sub to remove "assets" prefix, there're no problems in stat and open to access build folder.

@mholt
Copy link
Owner

mholt commented Apr 20, 2022

Thanks for the report. Just kind of a weird edge case. Can you please check and see if #335 does it for you? I was able to get it working using your repro code and archive, which was very helpful (thank you).

@WeidiDeng
Copy link
Contributor Author

Thanks you for your commit, it is indeed fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants