*: refactoring to support streams
when creating a manifest from, or validating, a stream like a tar archive, it requires thinking about some of the functions differently than walking a directory tree. This is the beginning of allowing for such features. Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
52a31746bf
commit
8074df1973
12 changed files with 535 additions and 134 deletions
12
check.go
12
check.go
|
@ -3,7 +3,6 @@ package mtree
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
)
|
||||
|
||||
|
@ -50,7 +49,8 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
|
|||
creator.curSet = nil
|
||||
}
|
||||
case RelativeType, FullType:
|
||||
info, err := os.Lstat(e.Path())
|
||||
filename := e.Path()
|
||||
info, err := os.Lstat(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -70,10 +70,16 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
|
|||
if keywords != nil && !inSlice(kv.Keyword(), keywords) {
|
||||
continue
|
||||
}
|
||||
curKeyVal, err := keywordFunc(filepath.Join(root, e.Path()), info)
|
||||
fh, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
curKeyVal, err := keywordFunc(filename, info, fh)
|
||||
if err != nil {
|
||||
fh.Close()
|
||||
return nil, err
|
||||
}
|
||||
fh.Close()
|
||||
if string(kv) != curKeyVal {
|
||||
failure := Failure{Path: e.Path(), Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()}
|
||||
result.Failures = append(result.Failures, failure)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue