Skip to content

Commit ed464af

Browse files
committed
*: xattr can Update()
This is a gnarly patchset that has been mashed together. It uncovered that some aspects of Check were never really working correctly for `xattr` keywords, but also the `Update()` had been left undone for a while. This includes some API changes around the `Keyword` and `KeyVal` types. Also I would like to update the signature for the `UpdateKeywordFunc` to just accept a `KeyVal` as an argugment, rather than a keyword AND the value. with this context there would be no need to guess on the value of what's passed to the xattr update function of whether it needs or already is base64 encoded. Signed-off-by: Vincent Batts <[email protected]>
1 parent fb4ec19 commit ed464af

19 files changed

+403
-263
lines changed

check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// simple walk of current directory, and imediately check it.
1313
// may not be parallelizable.
1414
func TestCheck(t *testing.T) {
15-
dh, err := Walk(".", nil, append(DefaultKeywords, "sha1"), nil)
15+
dh, err := Walk(".", nil, append(DefaultKeywords, []Keyword{"sha1", "xattr"}...), nil)
1616
if err != nil {
1717
t.Fatal(err)
1818
}

cmd/gomtree/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"fmt"
88
"io"
99
"io/ioutil"
10-
"log"
1110
"os"
1211
"strings"
1312

13+
"github.com/Sirupsen/logrus"
1414
"github.com/vbatts/go-mtree"
1515
)
1616

@@ -37,7 +37,7 @@ var (
3737
func main() {
3838
// so that defers cleanly exec
3939
if err := app(); err != nil {
40-
log.Fatal(err)
40+
logrus.Fatal(err)
4141
}
4242
}
4343

@@ -46,6 +46,7 @@ func app() error {
4646

4747
if *flDebug {
4848
os.Setenv("DEBUG", "1")
49+
logrus.SetLevel(logrus.DebugLevel)
4950
}
5051

5152
if *flVersion {

compare.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
197197
for _, kv := range oldKeys {
198198
key := kv.Keyword()
199199
// only add this diff if the new keys has this keyword
200-
if key != "tar_time" && key != "time" && key != "xattr" && HasKeyword(newKeys, key) == emptyKV {
200+
if key != "tar_time" && key != "time" && key != "xattr" && len(HasKeyword(newKeys, key)) == 0 {
201201
continue
202202
}
203203

@@ -216,7 +216,7 @@ func compareEntry(oldEntry, newEntry Entry) ([]KeyDelta, error) {
216216
for _, kv := range newKeys {
217217
key := kv.Keyword()
218218
// only add this diff if the old keys has this keyword
219-
if key != "tar_time" && key != "time" && key != "xattr" && HasKeyword(oldKeys, key) == emptyKV {
219+
if key != "tar_time" && key != "time" && key != "xattr" && len(HasKeyword(oldKeys, key)) == 0 {
220220
continue
221221
}
222222

debug.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

keywordfunc.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// io.Reader `r` is to the file stream for the file payload. While this
2222
// function takes an io.Reader, the caller needs to reset it to the beginning
2323
// for each new KeywordFunc
24-
type KeywordFunc func(path string, info os.FileInfo, r io.Reader) (KeyVal, error)
24+
type KeywordFunc func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error)
2525

2626
var (
2727
// KeywordFuncs is the map of all keywords (and the functions to produce them)
@@ -67,7 +67,7 @@ var (
6767
}
6868
)
6969
var (
70-
modeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
70+
modeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
7171
permissions := info.Mode().Perm()
7272
if os.ModeSetuid&info.Mode() > 0 {
7373
permissions |= (1 << 11)
@@ -78,93 +78,93 @@ var (
7878
if os.ModeSticky&info.Mode() > 0 {
7979
permissions |= (1 << 9)
8080
}
81-
return KeyVal(fmt.Sprintf("mode=%#o", permissions)), nil
81+
return []KeyVal{KeyVal(fmt.Sprintf("mode=%#o", permissions))}, nil
8282
}
83-
sizeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
83+
sizeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
8484
if sys, ok := info.Sys().(*tar.Header); ok {
8585
if sys.Typeflag == tar.TypeSymlink {
86-
return KeyVal(fmt.Sprintf("size=%d", len(sys.Linkname))), nil
86+
return []KeyVal{KeyVal(fmt.Sprintf("size=%d", len(sys.Linkname)))}, nil
8787
}
8888
}
89-
return KeyVal(fmt.Sprintf("size=%d", info.Size())), nil
89+
return []KeyVal{KeyVal(fmt.Sprintf("size=%d", info.Size()))}, nil
9090
}
91-
cksumKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
91+
cksumKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
9292
if !info.Mode().IsRegular() {
93-
return emptyKV, nil
93+
return nil, nil
9494
}
9595
sum, _, err := cksum(r)
9696
if err != nil {
97-
return emptyKV, err
97+
return nil, err
9898
}
99-
return KeyVal(fmt.Sprintf("cksum=%d", sum)), nil
99+
return []KeyVal{KeyVal(fmt.Sprintf("cksum=%d", sum))}, nil
100100
}
101101
hasherKeywordFunc = func(name string, newHash func() hash.Hash) KeywordFunc {
102-
return func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
102+
return func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
103103
if !info.Mode().IsRegular() {
104-
return emptyKV, nil
104+
return nil, nil
105105
}
106106
h := newHash()
107107
if _, err := io.Copy(h, r); err != nil {
108-
return emptyKV, err
108+
return nil, err
109109
}
110-
return KeyVal(fmt.Sprintf("%s=%x", KeywordSynonym(name), h.Sum(nil))), nil
110+
return []KeyVal{KeyVal(fmt.Sprintf("%s=%x", KeywordSynonym(name), h.Sum(nil)))}, nil
111111
}
112112
}
113-
tartimeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
114-
return KeyVal(fmt.Sprintf("tar_time=%d.%9.9d", info.ModTime().Unix(), 0)), nil
113+
tartimeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
114+
return []KeyVal{KeyVal(fmt.Sprintf("tar_time=%d.%9.9d", info.ModTime().Unix(), 0))}, nil
115115
}
116-
timeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
116+
timeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
117117
tSec := info.ModTime().Unix()
118118
tNano := info.ModTime().Nanosecond()
119-
return KeyVal(fmt.Sprintf("time=%d.%9.9d", tSec, tNano)), nil
119+
return []KeyVal{KeyVal(fmt.Sprintf("time=%d.%9.9d", tSec, tNano))}, nil
120120
}
121-
linkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
121+
linkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
122122
if sys, ok := info.Sys().(*tar.Header); ok {
123123
if sys.Linkname != "" {
124124
linkname, err := govis.Vis(sys.Linkname, DefaultVisFlags)
125125
if err != nil {
126-
return emptyKV, err
126+
return nil, nil
127127
}
128-
return KeyVal(fmt.Sprintf("link=%s", linkname)), nil
128+
return []KeyVal{KeyVal(fmt.Sprintf("link=%s", linkname))}, nil
129129
}
130-
return emptyKV, nil
130+
return nil, nil
131131
}
132132

133133
if info.Mode()&os.ModeSymlink != 0 {
134134
str, err := os.Readlink(path)
135135
if err != nil {
136-
return emptyKV, err
136+
return nil, nil
137137
}
138138
linkname, err := govis.Vis(str, DefaultVisFlags)
139139
if err != nil {
140-
return emptyKV, err
140+
return nil, nil
141141
}
142-
return KeyVal(fmt.Sprintf("link=%s", linkname)), nil
142+
return []KeyVal{KeyVal(fmt.Sprintf("link=%s", linkname))}, nil
143143
}
144-
return emptyKV, nil
144+
return nil, nil
145145
}
146-
typeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
146+
typeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
147147
if info.Mode().IsDir() {
148-
return "type=dir", nil
148+
return []KeyVal{"type=dir"}, nil
149149
}
150150
if info.Mode().IsRegular() {
151-
return "type=file", nil
151+
return []KeyVal{"type=file"}, nil
152152
}
153153
if info.Mode()&os.ModeSocket != 0 {
154-
return "type=socket", nil
154+
return []KeyVal{"type=socket"}, nil
155155
}
156156
if info.Mode()&os.ModeSymlink != 0 {
157-
return "type=link", nil
157+
return []KeyVal{"type=link"}, nil
158158
}
159159
if info.Mode()&os.ModeNamedPipe != 0 {
160-
return "type=fifo", nil
160+
return []KeyVal{"type=fifo"}, nil
161161
}
162162
if info.Mode()&os.ModeDevice != 0 {
163163
if info.Mode()&os.ModeCharDevice != 0 {
164-
return "type=char", nil
164+
return []KeyVal{"type=char"}, nil
165165
}
166-
return "type=block", nil
166+
return []KeyVal{"type=block"}, nil
167167
}
168-
return emptyKV, nil
168+
return nil, nil
169169
}
170170
)

keywordfuncs_bsd.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,58 @@ import (
1212
)
1313

1414
var (
15-
flagsKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
15+
flagsKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
1616
// ideally this will pull in from here https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2
17-
return emptyKV, nil
17+
return nil, nil
1818
}
1919

20-
unameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
20+
unameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
2121
if hdr, ok := info.Sys().(*tar.Header); ok {
22-
return KeyVal(fmt.Sprintf("uname=%s", hdr.Uname)), nil
22+
return []KeyVal{KeyVal(fmt.Sprintf("uname=%s", hdr.Uname))}, nil
2323
}
2424

2525
stat := info.Sys().(*syscall.Stat_t)
2626
u, err := user.LookupId(fmt.Sprintf("%d", stat.Uid))
2727
if err != nil {
28-
return emptyKV, err
28+
return nil, err
2929
}
30-
return KeyVal(fmt.Sprintf("uname=%s", u.Username)), nil
30+
return []KeyVal{KeyVal(fmt.Sprintf("uname=%s", u.Username))}, nil
3131
}
32-
gnameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
32+
gnameKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
3333
if hdr, ok := info.Sys().(*tar.Header); ok {
34-
return KeyVal(fmt.Sprintf("gname=%s", hdr.Gname)), nil
34+
return []KeyVal{KeyVal(fmt.Sprintf("gname=%s", hdr.Gname))}, nil
3535
}
3636

3737
stat := info.Sys().(*syscall.Stat_t)
3838
g, err := lookupGroupID(fmt.Sprintf("%d", stat.Gid))
3939
if err != nil {
40-
return emptyKV, err
40+
return nil, err
4141
}
42-
return KeyVal(fmt.Sprintf("gname=%s", g.Name)), nil
42+
return []KeyVal{KeyVal(fmt.Sprintf("gname=%s", g.Name))}, nil
4343
}
44-
uidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
44+
uidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
4545
if hdr, ok := info.Sys().(*tar.Header); ok {
46-
return KeyVal(fmt.Sprintf("uid=%d", hdr.Uid)), nil
46+
return []KeyVal{KeyVal(fmt.Sprintf("uid=%d", hdr.Uid))}, nil
4747
}
4848
stat := info.Sys().(*syscall.Stat_t)
49-
return KeyVal(fmt.Sprintf("uid=%d", stat.Uid)), nil
49+
return []KeyVal{KeyVal(fmt.Sprintf("uid=%d", stat.Uid))}, nil
5050
}
51-
gidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
51+
gidKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
5252
if hdr, ok := info.Sys().(*tar.Header); ok {
53-
return KeyVal(fmt.Sprintf("gid=%d", hdr.Gid)), nil
53+
return []KeyVal{KeyVal(fmt.Sprintf("gid=%d", hdr.Gid))}, nil
5454
}
5555
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
56-
return KeyVal(fmt.Sprintf("gid=%d", stat.Gid)), nil
56+
return []KeyVal{KeyVal(fmt.Sprintf("gid=%d", stat.Gid))}, nil
5757
}
58-
return emptyKV, nil
58+
return nil, nil
5959
}
60-
nlinkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
60+
nlinkKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
6161
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
62-
return KeyVal(fmt.Sprintf("nlink=%d", stat.Nlink)), nil
62+
return []KeyVal{KeyVal(fmt.Sprintf("nlink=%d", stat.Nlink))}, nil
6363
}
64-
return emptyKV, nil
64+
return nil, nil
6565
}
66-
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (KeyVal, error) {
67-
return emptyKV, nil
66+
xattrKeywordFunc = func(path string, info os.FileInfo, r io.Reader) ([]KeyVal, error) {
67+
return nil, nil
6868
}
6969
)

0 commit comments

Comments
 (0)