*: 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:
Vincent Batts 2016-04-15 18:39:18 -04:00 committed by Stephen Chung
parent 52a31746bf
commit 8074df1973
12 changed files with 535 additions and 134 deletions

View file

@ -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)