From d047c36dd09b6169bf27c244196e99bb5df54c3a Mon Sep 17 00:00:00 2001 From: Mitchell Date: Sat, 20 Mar 2021 01:37:03 -0400 Subject: Update documentation. Remove all traces of chdir from the steam library. Remove most linter complaints. --- steam/archive.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'steam/archive.go') diff --git a/steam/archive.go b/steam/archive.go index d997051..296defa 100644 --- a/steam/archive.go +++ b/steam/archive.go @@ -2,13 +2,14 @@ package steam import ( "archive/tar" + "fmt" "io" "os" "path/filepath" "strings" ) -func TarWalkfn(writer *tar.Writer) filepath.WalkFunc { +func tarWalkfn(writer *tar.Writer, prefix string) filepath.WalkFunc { return func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -24,13 +25,16 @@ func TarWalkfn(writer *tar.Writer) filepath.WalkFunc { } defer f.Close() - // Convert Windows paths to Unix paths - path = strings.Replace(path, "\\", "/", -1) + // Let's strip out all of the leading parts of the path + // to create a tarball realative to the root of the steam library + tarPth := strings.TrimPrefix(path, prefix) + tarPth = strings.ReplaceAll(tarPth, "\\", "/") + tarPth = strings.TrimPrefix(tarPth, "/") // TODO; See if tar.FileInfoheader() could be used instead // without the pathing issues I encountered h := &tar.Header{ - Name: path, + Name: tarPth, Size: info.Size(), // I don't like it... but it helps with platform compatibility Mode: 0664, @@ -44,10 +48,7 @@ func TarWalkfn(writer *tar.Writer) filepath.WalkFunc { _, err = io.Copy(writer, f) if err != nil { - // TODO: Figure out how to add more useful information to - // These errors - // fmt.Fprintln(os.Stderr, f.Name()) - return err + return fmt.Errorf("While copying %s: %w", path, err) } return nil -- cgit v1.2.3