Skip to content

Commit 593cfb6

Browse files
authored
Merge pull request #136 from vbatts/updatefunc_sig
updatefunc: simplify the function signature
2 parents 0b5038d + 9408f0f commit 593cfb6

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func Update(root string, dh *DirectoryHierarchy, keywords []Keyword, fs FsEval)
6262
logrus.Debugf("no UpdateKeywordFunc for %s; skipping", kv.Keyword())
6363
continue
6464
}
65-
if _, err := ukFunc(kv.Keyword(), pathname, kv.Value()); err != nil {
65+
if _, err := ukFunc(pathname, kv); err != nil {
6666
results = append(results, InodeDelta{
6767
diff: ErrorDifference,
6868
path: pathname,

updatefuncs.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// UpdateKeywordFunc is the signature for a function that will restore a file's
1414
// attributes. Where path is relative path to the file, and value to be
1515
// restored to.
16-
type UpdateKeywordFunc func(keyword Keyword, path string, value string) (os.FileInfo, error)
16+
type UpdateKeywordFunc func(path string, kv KeyVal) (os.FileInfo, error)
1717

1818
// UpdateKeywordFuncs is the registered list of functions to update file attributes.
1919
// Keyed by the keyword as it would show up in the manifest
@@ -26,8 +26,8 @@ var UpdateKeywordFuncs = map[Keyword]UpdateKeywordFunc{
2626
"xattr": xattrUpdateKeywordFunc,
2727
}
2828

29-
func uidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
30-
uid, err := strconv.Atoi(value)
29+
func uidUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
30+
uid, err := strconv.Atoi(kv.Value())
3131
if err != nil {
3232
return nil, err
3333
}
@@ -37,8 +37,8 @@ func uidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, err
3737
return os.Lstat(path)
3838
}
3939

40-
func gidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
41-
gid, err := strconv.Atoi(value)
40+
func gidUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
41+
gid, err := strconv.Atoi(kv.Value())
4242
if err != nil {
4343
return nil, err
4444
}
@@ -48,12 +48,12 @@ func gidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, err
4848
return os.Lstat(path)
4949
}
5050

51-
func modeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
52-
vmode, err := strconv.ParseInt(value, 8, 32)
51+
func modeUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
52+
vmode, err := strconv.ParseInt(kv.Value(), 8, 32)
5353
if err != nil {
5454
return nil, err
5555
}
56-
logrus.Debugf("path: %q, value: %q, vmode: %o", path, value, vmode)
56+
logrus.Debugf("path: %q, kv.Value(): %q, vmode: %o", path, kv.Value(), vmode)
5757
if err := os.Chmod(path, os.FileMode(vmode)); err != nil {
5858
return nil, err
5959
}
@@ -63,13 +63,13 @@ func modeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, er
6363
// since tar_time will only be second level precision, then when restoring the
6464
// filepath from a tar_time, then compare the seconds first and only Chtimes if
6565
// the seconds value is different.
66-
func tartimeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
66+
func tartimeUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
6767
info, err := os.Lstat(path)
6868
if err != nil {
6969
return nil, err
7070
}
7171

72-
v := strings.SplitN(value, ".", 2)
72+
v := strings.SplitN(kv.Value(), ".", 2)
7373
if len(v) != 2 {
7474
return nil, fmt.Errorf("expected a number like 1469104727.000000000")
7575
}
@@ -92,8 +92,8 @@ func tartimeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo,
9292
}
9393

9494
// this is nano second precision
95-
func timeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
96-
v := strings.SplitN(value, ".", 2)
95+
func timeUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
96+
v := strings.SplitN(kv.Value(), ".", 2)
9797
if len(v) != 2 {
9898
return nil, fmt.Errorf("expected a number like 1469104727.871937272")
9999
}

updatefuncs_linux.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
"github.com/vbatts/go-mtree/xattr"
1010
)
1111

12-
func xattrUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
13-
buf, err := base64.StdEncoding.DecodeString(value)
12+
func xattrUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
13+
buf, err := base64.StdEncoding.DecodeString(kv.Value())
1414
if err != nil {
1515
return nil, err
1616
}
17-
if err := xattr.Set(path, keyword.Suffix(), buf); err != nil {
17+
if err := xattr.Set(path, kv.Keyword().Suffix(), buf); err != nil {
1818
return nil, err
1919
}
2020
return os.Lstat(path)

updatefuncs_unsupported.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ package mtree
44

55
import "os"
66

7-
func xattrUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) {
7+
func xattrUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
88
return os.Lstat(path)
99
}

0 commit comments

Comments
 (0)