1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2025-06-30 21:58:30 +00:00

check: an initial pass at a validation check

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2016-03-23 16:58:16 -04:00
parent 6db2f462a1
commit 2fd41fb43f
5 changed files with 101 additions and 13 deletions

View file

@ -8,6 +8,7 @@ import (
)
type Result struct {
// XXX perhaps this is a list of the failed files and keywords?
}
var ErrNotAllClear = fmt.Errorf("some keyword check failed validation")
@ -24,6 +25,7 @@ func Check(root string, dh *DirectoryHierarchy) (*Result, error) {
}
sort.Sort(byPos(creator.DH.Entries))
var failed bool
for _, e := range creator.DH.Entries {
switch e.Type {
case SpecialType:
@ -32,20 +34,39 @@ func Check(root string, dh *DirectoryHierarchy) (*Result, error) {
} else if e.Name == "/unset" {
creator.curSet = nil
}
case DotDotType:
// TODO step
case RelativeType:
// TODO determine path, and check keywords
// or maybe to Chdir when type=dir?
case FullType:
info, err := os.Lstat(filepath.Join(root, e.Name))
case RelativeType, FullType:
info, err := os.Lstat(filepath.Join(root, e.Path()))
if err != nil {
return nil, err
}
// TODO check against keywords present
_ = info
var kvs KeyVals
if creator.curSet != nil {
kvs = MergeSet(creator.curSet.Keywords, e.Keywords)
} else {
kvs = NewKeyVals(e.Keywords)
}
for _, kv := range kvs {
keywordFunc, ok := KeywordFuncs[kv.Keyword()]
if !ok {
return nil, fmt.Errorf("Unknown keyword %q for file %q", kv.Keyword(), e.Path())
}
curKeyVal, err := keywordFunc(filepath.Join(root, e.Path()), info)
if err != nil {
return nil, err
}
if string(kv) != curKeyVal {
failed = true
fmt.Printf("%q: keyword %q: expected %s; got %s", e.Path(), kv.Keyword(), kv.Value(), KeyVal(curKeyVal).Value())
}
}
}
}
if failed {
return nil, ErrNotAllClear
}
return nil, nil
}