1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
}
|