1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-21 07:55:44 +00:00

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:
Stephen Chung 2016-07-26 09:02:30 -04:00
parent d6b0881515
commit 2facedc401
16 changed files with 41 additions and 9 deletions

View file

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

View file

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

View file

View file

View file

@ -0,0 +1 @@
some spacious text

View file

@ -0,0 +1 @@
some nice text

View file

View file

View file

View file

View file

1
testdata/dirwithbrokenlink/dir1/badlink vendored Symbolic link
View file

@ -0,0 +1 @@
badfile

View file

@ -0,0 +1 @@
../../goodfile

View file

@ -0,0 +1 @@
link text

0
testdata/dirwithbrokenlink/file1 vendored Normal file
View file

0
testdata/dirwithbrokenlink/file2 vendored Normal file
View file