1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 00:15:39 +00:00

updatefunc: simplify the function signature

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-06-26 14:24:10 -04:00
parent 0b5038d0bc
commit 9408f0f4c0
Signed by: vbatts
GPG key ID: 10937E57733F1362
4 changed files with 17 additions and 17 deletions

View file

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

View file

@ -13,7 +13,7 @@ import (
// UpdateKeywordFunc is the signature for a function that will restore a file's // UpdateKeywordFunc is the signature for a function that will restore a file's
// attributes. Where path is relative path to the file, and value to be // attributes. Where path is relative path to the file, and value to be
// restored to. // restored to.
type UpdateKeywordFunc func(keyword Keyword, path string, value string) (os.FileInfo, error) type UpdateKeywordFunc func(path string, kv KeyVal) (os.FileInfo, error)
// UpdateKeywordFuncs is the registered list of functions to update file attributes. // UpdateKeywordFuncs is the registered list of functions to update file attributes.
// Keyed by the keyword as it would show up in the manifest // Keyed by the keyword as it would show up in the manifest
@ -26,8 +26,8 @@ var UpdateKeywordFuncs = map[Keyword]UpdateKeywordFunc{
"xattr": xattrUpdateKeywordFunc, "xattr": xattrUpdateKeywordFunc,
} }
func uidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func uidUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
uid, err := strconv.Atoi(value) uid, err := strconv.Atoi(kv.Value())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -37,8 +37,8 @@ func uidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, err
return os.Lstat(path) return os.Lstat(path)
} }
func gidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func gidUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
gid, err := strconv.Atoi(value) gid, err := strconv.Atoi(kv.Value())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -48,12 +48,12 @@ func gidUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, err
return os.Lstat(path) return os.Lstat(path)
} }
func modeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func modeUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
vmode, err := strconv.ParseInt(value, 8, 32) vmode, err := strconv.ParseInt(kv.Value(), 8, 32)
if err != nil { if err != nil {
return nil, err return nil, err
} }
logrus.Debugf("path: %q, value: %q, vmode: %o", path, value, vmode) logrus.Debugf("path: %q, kv.Value(): %q, vmode: %o", path, kv.Value(), vmode)
if err := os.Chmod(path, os.FileMode(vmode)); err != nil { if err := os.Chmod(path, os.FileMode(vmode)); err != nil {
return nil, err return nil, err
} }
@ -63,13 +63,13 @@ func modeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, er
// since tar_time will only be second level precision, then when restoring the // since tar_time will only be second level precision, then when restoring the
// filepath from a tar_time, then compare the seconds first and only Chtimes if // filepath from a tar_time, then compare the seconds first and only Chtimes if
// the seconds value is different. // the seconds value is different.
func tartimeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func tartimeUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
info, err := os.Lstat(path) info, err := os.Lstat(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
v := strings.SplitN(value, ".", 2) v := strings.SplitN(kv.Value(), ".", 2)
if len(v) != 2 { if len(v) != 2 {
return nil, fmt.Errorf("expected a number like 1469104727.000000000") return nil, fmt.Errorf("expected a number like 1469104727.000000000")
} }
@ -92,8 +92,8 @@ func tartimeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo,
} }
// this is nano second precision // this is nano second precision
func timeUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func timeUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
v := strings.SplitN(value, ".", 2) v := strings.SplitN(kv.Value(), ".", 2)
if len(v) != 2 { if len(v) != 2 {
return nil, fmt.Errorf("expected a number like 1469104727.871937272") return nil, fmt.Errorf("expected a number like 1469104727.871937272")
} }

View file

@ -9,12 +9,12 @@ import (
"github.com/vbatts/go-mtree/xattr" "github.com/vbatts/go-mtree/xattr"
) )
func xattrUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func xattrUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
buf, err := base64.StdEncoding.DecodeString(value) buf, err := base64.StdEncoding.DecodeString(kv.Value())
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := xattr.Set(path, keyword.Suffix(), buf); err != nil { if err := xattr.Set(path, kv.Keyword().Suffix(), buf); err != nil {
return nil, err return nil, err
} }
return os.Lstat(path) return os.Lstat(path)

View file

@ -4,6 +4,6 @@ package mtree
import "os" import "os"
func xattrUpdateKeywordFunc(keyword Keyword, path, value string) (os.FileInfo, error) { func xattrUpdateKeywordFunc(path string, kv KeyVal) (os.FileInfo, error) {
return os.Lstat(path) return os.Lstat(path)
} }