mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-21 16:05:40 +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:
parent
d6b0881515
commit
2facedc401
16 changed files with 41 additions and 9 deletions
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) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.")
|
||||||
|
|
0
testdata/dirwithbrokenlink/ file with spaces
vendored
Normal file
0
testdata/dirwithbrokenlink/ file with spaces
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/dir4/deepfile
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/dir4/deepfile
vendored
Normal file
1
testdata/dirwithbrokenlink/deepdir/dir3/dir4/dir5/dir6/deeperfile
vendored
Normal file
1
testdata/dirwithbrokenlink/deepdir/dir3/dir4/dir5/dir6/deeperfile
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
some spacious text
|
1
testdata/dirwithbrokenlink/deepdir/dir3/dir4/dir5/dir7/deeperfile
vendored
Normal file
1
testdata/dirwithbrokenlink/deepdir/dir3/dir4/dir5/dir7/deeperfile
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
some nice text
|
0
testdata/dirwithbrokenlink/deepdir/dir3/file
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/file
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/file6
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/file6
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/file7
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/dir3/file7
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/this_is_a_file
vendored
Normal file
0
testdata/dirwithbrokenlink/deepdir/this_is_a_file
vendored
Normal file
0
testdata/dirwithbrokenlink/dir1/.hiddenfile
vendored
Normal file
0
testdata/dirwithbrokenlink/dir1/.hiddenfile
vendored
Normal file
1
testdata/dirwithbrokenlink/dir1/badlink
vendored
Symbolic link
1
testdata/dirwithbrokenlink/dir1/badlink
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
badfile
|
1
testdata/dirwithbrokenlink/dir1/dir2/.hidden/goodlink
vendored
Symbolic link
1
testdata/dirwithbrokenlink/dir1/dir2/.hidden/goodlink
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../../goodfile
|
1
testdata/dirwithbrokenlink/dir1/goodfile
vendored
Normal file
1
testdata/dirwithbrokenlink/dir1/goodfile
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
link text
|
0
testdata/dirwithbrokenlink/file1
vendored
Normal file
0
testdata/dirwithbrokenlink/file1
vendored
Normal file
0
testdata/dirwithbrokenlink/file2
vendored
Normal file
0
testdata/dirwithbrokenlink/file2
vendored
Normal file
Loading…
Reference in a new issue