blob: 74eaba45020797e1c20be6c4dfd5d3c4048ac91e (
plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// On-cloud data structures
package arq
import (
"fmt"
"os"
"time"
)
// plist data structures
type computerInfo struct {
UserName string `plist:"userName"`
ComputerName string `plist:"computerName"`
}
type folderInfo struct {
BucketUUID string
BucketName string
ComputerUUID string
LocalPath string
LocalMountPoint string
// don't care about IgnoredRelativePaths or Excludes
}
type reflog struct {
OldHeadSHA1 string `plist:"oldHeadSHA1"`
NewHeadSHA1 string `plist:"newHeadSHA1"`
}
// binary data structures
type score [20]byte
type sscore struct {
Score score `arq:"HexScore"`
StretchKey bool // v4+
}
type tag string
type commit struct {
Tag tag `arq:"CommitV005"`
Author string
Comment string
ParentCommits []sscore
Tree sscore
Location string
MergeCommonAncestor sscore
CreateTime time.Time
Failed []failed // v3+
BucketXML []byte // v5+
}
type tree struct {
Tag tag `arq:"TreeV015"`
CompressXattr bool
CompressACL bool
Xattr sscore
XattrSize uint64
ACL sscore
Uid int32
Gid int32
Mode int32
Mtime unixTime
Flags int64
FinderFlags int32
XFinderFlags int32
StDev int32
StIno int32
StNlink uint32
StRdev int32
Ctime unixTime
StBlocks int64
StBlksize uint32
AggrSize uint64
Crtime unixTime
Nodes []*nameNode `arq:"count32"`
}
type nameNode struct {
Name string
Node node
}
type node struct {
IsTree bool
CompressData bool
CompressXattr bool
CompressACL bool
Blob []sscore `arq:"count32"`
UncompressedSize uint64
Thumbnail sscore
Preview sscore
Xattr sscore
XattrSize uint64
ACL sscore
Uid int32
Gid int32
Mode int32
Mtime unixTime
Flags int64
FinderFlags int32
XFinderFlags int32
FinderFileType string
FinderFileCreator string
IsExtHidden bool
StDev int32
StIno int32
StNlink uint32
StRdev int32
Ctime unixTime
CreateTime unixTime
StBlocks int64
StBlksize uint32
}
func fileMode(m int32) os.FileMode {
const (
// Darwin file mode.
S_IFBLK = 0x6000
S_IFCHR = 0x2000
S_IFDIR = 0x4000
S_IFIFO = 0x1000
S_IFLNK = 0xa000
S_IFMT = 0xf000
S_IFREG = 0x8000
S_IFSOCK = 0xc000
S_IFWHT = 0xe000
S_ISGID = 0x400
S_ISTXT = 0x200
S_ISUID = 0x800
S_ISVTX = 0x200
)
mode := os.FileMode(m & 0777)
switch m & S_IFMT {
case S_IFBLK, S_IFWHT:
mode |= os.ModeDevice
case S_IFCHR:
mode |= os.ModeDevice | os.ModeCharDevice
case S_IFDIR:
mode |= os.ModeDir
case S_IFIFO:
mode |= os.ModeNamedPipe
case S_IFLNK:
mode |= os.ModeSymlink
case S_IFREG:
// nothing to do
case S_IFSOCK:
mode |= os.ModeSocket
}
if m&S_ISGID != 0 {
mode |= os.ModeSetgid
}
if m&S_ISUID != 0 {
mode |= os.ModeSetuid
}
if m&S_ISVTX != 0 {
mode |= os.ModeSticky
}
return mode
}
type unixTime struct {
Sec int64
Nsec int64
}
func (t *unixTime) Time() time.Time {
return time.Unix(t.Sec, t.Nsec)
}
type failed struct {
Path string
Error string
}
type ientry struct {
File string
Offset int64
Size int64
Score score
}
func (s score) Equal(t score) bool {
for i := range s {
if s[i] != t[i] {
return false
}
}
return true
}
func (s score) String() string {
return fmt.Sprintf("%x", s[:])
}
func binaryScore(b []byte) score {
if len(b) < 20 {
panic("BinaryScore: not enough data")
}
var sc score
copy(sc[:], b)
return sc
}
func hexScore(b string) score {
if len(b) < 40 {
panic("HexScore: not enough data")
}
var sc score
for i := 0; i < 40; i++ {
ch := b[i]
if '0' <= ch && ch <= '9' {
ch -= '0'
} else if 'a' <= ch && ch <= 'f' {
ch -= 'a' - 10
} else {
panic("HexScore: invalid lower hex digit")
}
if i%2 == 0 {
ch <<= 4
}
sc[i/2] |= ch
}
return sc
}
func (ss sscore) String() string {
str := ss.Score.String()
if ss.StretchKey {
str += "Y"
}
return str
}
|