aboutsummaryrefslogtreecommitdiff
path: root/steam/archive.go
diff options
context:
space:
mode:
authorMitchell <mitch@riedstra.dev>2021-03-20 01:37:03 -0400
committerMitchell <mitch@riedstra.dev>2021-03-20 01:37:03 -0400
commitd047c36dd09b6169bf27c244196e99bb5df54c3a (patch)
tree5103e1951bd58bbef54c90a13c199e8d1d866492 /steam/archive.go
parent0e62a3b46b25e7c101b14ed44235f3c276982fc0 (diff)
downloadsteam-export-d047c36dd09b6169bf27c244196e99bb5df54c3a.tar.gz
steam-export-d047c36dd09b6169bf27c244196e99bb5df54c3a.tar.xz
Update documentation. Remove all traces of chdir from the steam library. Remove most linter complaints.
Diffstat (limited to 'steam/archive.go')
-rw-r--r--steam/archive.go17
1 files changed, 9 insertions, 8 deletions
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