From 5418292142d321a49461be6639bb2d52cac7a64a Mon Sep 17 00:00:00 2001 From: Aaron Meihm Date: Wed, 30 Dec 2015 12:58:56 -0600 Subject: [PATCH] support symlink resolution during file search Closes #3 --- src/scribe/filecontent.go | 27 +++++++++++++++++++++++++++ test/filecontent/data/testfile2 | 1 + test/filecontent/test-template.json | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 120000 test/filecontent/data/testfile2 diff --git a/src/scribe/filecontent.go b/src/scribe/filecontent.go index b9adc47..268515d 100644 --- a/src/scribe/filecontent.go +++ b/src/scribe/filecontent.go @@ -235,6 +235,17 @@ func (s *simpleFileLocator) locate(target string, useRegexp bool) error { return s.locateInner(target, useRegexp, "") } +func (s *simpleFileLocator) symFollowIsRegular(path string) (bool, error) { + fi, err := os.Stat(path) + if err != nil { + return false, err + } + if fi.Mode().IsRegular() { + return true, nil + } + return false, nil +} + func (s *simpleFileLocator) locateInner(target string, useRegexp bool, path string) error { var ( spath string @@ -288,6 +299,22 @@ func (s *simpleFileLocator) locateInner(target string, useRegexp bool, path stri s.matches = append(s.matches, fname) } } + } else if (x.Mode() & os.ModeSymlink) > 0 { + isregsym, err := s.symFollowIsRegular(fname) + if err != nil { + return err + } + if isregsym { + if !useRegexp { + if x.Name() == target { + s.matches = append(s.matches, fname) + } + } else { + if re.MatchString(x.Name()) { + s.matches = append(s.matches, fname) + } + } + } } } return nil diff --git a/test/filecontent/data/testfile2 b/test/filecontent/data/testfile2 new file mode 120000 index 0000000..4b94bce --- /dev/null +++ b/test/filecontent/data/testfile2 @@ -0,0 +1 @@ +testfile1 \ No newline at end of file diff --git a/test/filecontent/test-template.json b/test/filecontent/test-template.json index 5a5dd07..26c3133 100644 --- a/test/filecontent/test-template.json +++ b/test/filecontent/test-template.json @@ -49,6 +49,15 @@ } }, + { + "object": "testfile2-version", + "filecontent": { + "path": "${root}", + "file": ".*file2", + "expression": "^Version = (\\S+)" + } + }, + { "object": "anyfile", "filecontent": { @@ -134,6 +143,17 @@ } }, + { + "test": "filecontent4", + "description": "version is ok", + "expectedresult": false, + "object": "testfile2-version", + "evr": { + "operation": "<", + "value": "0.4z" + } + }, + { "test": "anyfile0", "expectedresult": true,