Merge pull request #4 from ameihm0912/master

Better handling of symlinks and content scanning
This commit is contained in:
Aaron Meihm 2015-12-30 13:02:31 -06:00
Родитель 0934496028 5418292142
Коммит 579fe665d8
3 изменённых файлов: 53 добавлений и 1 удалений

Просмотреть файл

@ -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
@ -309,7 +336,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 +347,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{}

Просмотреть файл

@ -0,0 +1 @@
testfile1

Просмотреть файл

@ -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,