1
0
Fork 0
mirror of https://github.com/vbatts/go-mtree.git synced 2024-11-22 16:25:38 +00:00

Merge pull request #62 from stephen679/evaluating_symlink

check: functionality for symlinks
This commit is contained in:
Vincent Batts 2016-08-10 15:22:32 -04:00 committed by GitHub
commit 7dbe113002
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) { if keywords != nil && !inSlice(kv.Keyword(), keywords) {
continue continue
} }
fh, err := os.Open(pathname)
if err != nil { var curKeyVal string
return nil, err if info.Mode().IsRegular() {
} fh, err := os.Open(pathname)
curKeyVal, err := keywordFunc(pathname, info, fh) if err != nil {
if err != nil { return nil, err
}
curKeyVal, err = keywordFunc(pathname, info, fh)
if err != nil {
fh.Close()
return nil, err
}
fh.Close() fh.Close()
return nil, err } else {
curKeyVal, err = keywordFunc(pathname, info, nil)
if err != nil {
return nil, err
}
} }
fh.Close()
if string(kv) != curKeyVal { if string(kv) != curKeyVal {
failure := Failure{Path: pathname, Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()} failure := Failure{Path: pathname, Keyword: kv.Keyword(), Expected: kv.Value(), Got: KeyVal(curKeyVal).Value()}
result.Failures = append(result.Failures, failure) result.Failures = append(result.Failures, failure)
@ -174,7 +183,7 @@ func TarCheck(tarDH, dh *DirectoryHierarchy, keywords []string) (*Result, error)
} }
for _, kv := range kvs { for _, kv := range kvs {
// TODO: keep track of symlinks
if _, ok := KeywordFuncs[kv.Keyword()]; !ok { if _, ok := KeywordFuncs[kv.Keyword()]; !ok {
return nil, fmt.Errorf("Unknown keyword %q for file %q", kv.Keyword(), pathname) 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 // https://github.com/vbatts/go-mtree/issues/8
func TestTimeComparison(t *testing.T) { func TestTimeComparison(t *testing.T) {
dir, err := ioutil.TempDir("", "test-time.") 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