Commit ffebf0b6 authored by Boris Mühmer's avatar Boris Mühmer

corrected gdp.Walk() to return a stream of .git pathes

parent fe9522d1
......@@ -18,27 +18,29 @@ func NewGitDirectoryPath(rootPath string) *GitDirectoryPath {
}
// Walk ...
func (g *GitDirectoryPath) Walk(done <-chan bool) (chan<- string, error) {
func (g *GitDirectoryPath) Walk() <-chan string {
pathStream := make(chan string)
defer close(pathStream)
if err := filepath.Walk(g.rootPath,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
return nil
}
if info.Name() != ".git" {
go func() {
defer close(pathStream)
filepath.Walk(g.rootPath,
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
return nil
}
if info.Name() != ".git" {
return nil
}
pathStream <- path
return nil
}
pathStream <- path
return nil
}); err != nil {
return nil, err
}
return pathStream, nil
})
}()
return pathStream
}
// GitDirectory returns all .git directories below a given rootPath.
......
......@@ -8,17 +8,23 @@ import (
"testing"
)
func TestJugglerSearchProjects(t *testing.T) {
func dirPath() (string, error) {
//basePath := "/home/MUEHMER/bsmr/repositories"
basePath := "repositories"
usr, err := user.Current()
if err != nil {
t.Fatalf("user.Current() failed: %s", err)
return "", err
}
dirPath := path.Join(usr.HomeDir, basePath)
return path.Join(usr.HomeDir, basePath), nil
}
func TestJugglerSearchProjectsNormal(t *testing.T) {
dirPath, err := dirPath()
if err != nil {
t.Fatalf("dirPath() failed: %s", err)
}
err = filepath.Walk(dirPath,
func(path string, info os.FileInfo, err error) error {
......@@ -39,6 +45,18 @@ func TestJugglerSearchProjects(t *testing.T) {
}
}
func TestJugglerSearchProjectsStream(t *testing.T) {
dirPath, err := dirPath()
if err != nil {
t.Fatalf("dirPath() failed: %s", err)
}
gdp := NewGitDirectoryPath(dirPath)
for path := range gdp.Walk() {
t.Logf("path: %s", path)
}
}
func TestJugglerProcessProjectsSequential(t *testing.T) {
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment