remove searchpath package

This commit is contained in:
mattes 2014-08-11 03:48:04 +02:00
parent a45e244a71
commit 13acfe3e2e
2 changed files with 0 additions and 74 deletions

View File

@ -1,46 +0,0 @@
package searchpath
import (
"errors"
"io/ioutil"
"regexp"
)
var searchpath []string
func SetSearchPath(paths ...string) {
searchpath = paths
}
func AppendSearchPath(path string) {
searchpath = append(searchpath, path)
}
func PrependSearchPath(path string) {
searchpath = append((searchpath)[:0], append([]string{path}, (searchpath)[0:]...)...)
}
func GetSearchPath() []string {
return searchpath
}
// FindPath scans files in the search paths and
// returns the path where the regex matches at least twice
func FindPath(regex *regexp.Regexp) (path string, err error) {
count := 0
for _, path := range searchpath {
// TODO refactor ioutil.ReadDir to read only first files per dir
files, err := ioutil.ReadDir(path)
if err == nil {
for _, file := range files {
if regex.MatchString(file.Name()) {
count += 1
}
if count >= 2 {
return path, nil
}
}
}
}
return "", errors.New("no path found")
}

View File

@ -1,28 +0,0 @@
package searchpath
import (
"testing"
)
func TestSetSearchPath(t *testing.T) {
SetSearchPath("a")
if len(searchpath) != 1 || searchpath[0] != "a" {
t.Error("SetSearchPath failed")
}
}
func TestAppendSearchPath(t *testing.T) {
SetSearchPath("a")
AppendSearchPath("b")
if len(searchpath) != 2 || searchpath[0] != "a" || searchpath[1] != "b" {
t.Error("AppendSearchPath failed")
}
}
func TestPrependSearchPath(t *testing.T) {
SetSearchPath("a")
PrependSearchPath("b")
if len(searchpath) != 2 || searchpath[0] != "b" || searchpath[1] != "a" {
t.Error("PrependSearchPath failed")
}
}