From 59f11e2a17fd2e1a4b0cc2fcfbca9279668560b6 Mon Sep 17 00:00:00 2001 From: Aaron Meihm Date: Wed, 30 Dec 2015 11:47:30 -0600 Subject: [PATCH 1/2] use ReadLine instead of ReadString with fileContentCheck --- src/scribe/filecontent.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/scribe/filecontent.go b/src/scribe/filecontent.go index 6304f0f..b9adc47 100644 --- a/src/scribe/filecontent.go +++ b/src/scribe/filecontent.go @@ -309,7 +309,10 @@ func fileContentCheck(path string, regex string) ([]matchLine, error) { rdr := bufio.NewReader(fd) ret := make([]matchLine, 0) for { - ln, err := rdr.ReadString('\n') + // XXX Ignore potential partial reads (prefix) here, for lines + // with excessive length we will just treat it as multiple + // lines + buf, _, err := rdr.ReadLine() if err != nil { if err == io.EOF { break @@ -317,6 +320,7 @@ func fileContentCheck(path string, regex string) ([]matchLine, error) { return nil, err } } + ln := string(buf) mtch := re.FindStringSubmatch(ln) if len(mtch) > 0 { newmatch := matchLine{} From 5418292142d321a49461be6639bb2d52cac7a64a Mon Sep 17 00:00:00 2001 From: Aaron Meihm Date: Wed, 30 Dec 2015 12:58:56 -0600 Subject: [PATCH 2/2] 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,