diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2020-12-25 12:16:40 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2020-12-25 12:17:05 -0500 |
| commit | f26c564dcadf71e7c4c8fe99555fb7d038216140 (patch) | |
| tree | 7e8692276f30d96539310ad2a4a274eb4ae8b8ea | |
| parent | 40bf960edf568a65cf49d295fde946518bcf20fd (diff) | |
| download | steam-export-f26c564dcadf71e7c4c8fe99555fb7d038216140.tar.gz steam-export-f26c564dcadf71e7c4c8fe99555fb7d038216140.tar.xz | |
Flush the tarwriter before we return
| -rw-r--r-- | steam/filelisting.go | 26 | ||||
| -rw-r--r-- | steam/package.go | 2 | ||||
| -rw-r--r-- | steam/update.go | 70 |
3 files changed, 97 insertions, 1 deletions
diff --git a/steam/filelisting.go b/steam/filelisting.go new file mode 100644 index 0000000..f94319e --- /dev/null +++ b/steam/filelisting.go @@ -0,0 +1,26 @@ +package steam + +import ( + "path/filepath" + "os" +) + +func fileListing(pth string) (map[string]struct{}, error) { + out := map[string]struct{}{} + err := filepath.Walk(pth, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if info.Mode().IsRegular() { + out[path] = struct{}{} + } + + return nil + }) + if err != nil { + return nil, err + } + + return out, nil +} diff --git a/steam/package.go b/steam/package.go index 9000cba..cff086e 100644 --- a/steam/package.go +++ b/steam/package.go @@ -26,7 +26,7 @@ func (g *Game) Package(wr io.Writer) error { } } - return nil + return twriter.Flush() } func (l *Library) Extract(r io.Reader) error { diff --git a/steam/update.go b/steam/update.go new file mode 100644 index 0000000..b3e621e --- /dev/null +++ b/steam/update.go @@ -0,0 +1,70 @@ +package steam + +import ( + "archive/tar" + "io" + "os" + "strings" + "path/filepath" +) + +func (l *Library) ExtractUpdate(r io.Reader) error { + if err := os.Chdir(l.Folder); err != nil { + return err + } + + // withinArchive := map[string]struct{}{} + // onDisk, err := fileListing( + + treader := tar.NewReader(r) + + for { + hdr, err := treader.Next() + if err == io.EOF { + // We've reached the end! Whoee + break + } + if err != nil { + return err + } + + // Fix windows slashes... + fileName := strings.Replace(hdr.Name, "\\", "/", -1) + + info := hdr.FileInfo() + if info.IsDir() { + // I don't like hard-coded permissions but it + // it helps with overall platform compatibility + if err = os.MkdirAll(fileName, 0775); err != nil { + return err + } + continue + } + + if err = os.MkdirAll(filepath.Dir(fileName), 0775); err != nil { + return err + } + + fi, err := os.Stat(fileName) + if !os.IsNotExist(err) { + // If the file in the archive is not newer, skip + if !info.ModTime().After(fi.ModTime()) { + continue + } + } + + // Create a file handle to work with + f, err := os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0664) + if err != nil { + return err + } + if _, err := io.Copy(f, treader); err != nil { + return err + } + f.Close() + + } + + return nil +} + |
