mirror of https://github.com/vbatts/go-mtree.git
check: functionality for symlinks
Default behavior (according to upstream mtree) for validating symlinks is to just validate the link itself, not to follow it. Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
parent
d6b0881515
commit
2facedc401
27
check.go
27
check.go
|
@ -84,16 +84,25 @@ func Check(root string, dh *DirectoryHierarchy, keywords []string) (*Result, err
|
|||
if keywords != nil && !inSlice(kv.Keyword(), keywords) {
|
||||
continue
|
||||
}
|
||||
fh, err := os.Open(pathname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
curKeyVal, err := keywordFunc(pathname, info, fh)
|
||||
if err != nil {
|
||||
|
||||
var curKeyVal string
|
||||
if info.Mode().IsRegular() {
|
||||
fh, err := os.Open(pathname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
curKeyVal, err = keywordFunc(pathname, info, fh)
|
||||
if err != nil {
|
||||
fh.Close()
|
||||
return nil, err
|
||||
}
|
||||
fh.Close()
|
||||
return nil, err
|
||||
} else {
|
||||
curKeyVal, err = keywordFunc(pathname, info, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
fh.Close()
|
||||
if string(kv) != curKeyVal {
|
||||
failure := Failure{Path: pathname, Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()}
|
||||
result.Failures = append(result.Failures, failure)
|
||||
|
@ -174,7 +183,7 @@ func TarCheck(tarDH, dh *DirectoryHierarchy, keywords []string) (*Result, error)
|
|||
}
|
||||
|
||||
for _, kv := range kvs {
|
||||
|
||||
// TODO: keep track of symlinks
|
||||
if _, ok := KeywordFuncs[kv.Keyword()]; !ok {
|
||||
return nil, fmt.Errorf("Unknown keyword %q for file %q", kv.Keyword(), pathname)
|
||||
}
|
||||
|
|
|
@ -97,6 +97,24 @@ func ExampleCheck() {
|
|||
}
|
||||
}
|
||||
|
||||
// Tests default action for evaluating a symlink, which is just to compare the
|
||||
// link itself, not to follow it
|
||||
func TestDefaultBrokenLink(t *testing.T) {
|
||||
dh, err := Walk("./testdata/dirwithbrokenlink", nil, append(DefaultKeywords, "sha1"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := Check("./testdata/dirwithbrokenlink", dh, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res != nil && len(res.Failures) > 0 {
|
||||
for _, f := range res.Failures {
|
||||
t.Error(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/vbatts/go-mtree/issues/8
|
||||
func TestTimeComparison(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "test-time.")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
some spacious text
|
|
@ -0,0 +1 @@
|
|||
some nice text
|
|
@ -0,0 +1 @@
|
|||
badfile
|
|
@ -0,0 +1 @@
|
|||
../../goodfile
|
|
@ -0,0 +1 @@
|
|||
link text
|
Loading…
Reference in New Issue