forked from kevinburke/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba47ac0
commit c0c4a9b
Showing
10 changed files
with
493 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package xbindata | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"github.com/moisespsena-go/xbindata/walker" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
func (i ManyConfigInput) Walked(visited *map[string]bool, recursive bool, cb walker.WalkCallback) (err error) { | ||
cmd := exec.Command("go", "run", filepath.Join(i.Path, ".xbwalk", "main.go")) | ||
cmd.Dir = i.Path | ||
cmd.Env = os.Environ() | ||
fr, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return fmt.Errorf("pipe stdout failed: %v", err) | ||
} | ||
defer fr.Close() | ||
cmd.Stderr = os.Stderr | ||
|
||
var scanner = bufio.NewScanner(fr) | ||
|
||
if err = cmd.Start(); err != nil { | ||
return fmt.Errorf("start failed: %v", err) | ||
} | ||
|
||
var closed bool | ||
defer func() { | ||
if !closed { | ||
cmd.Process.Kill() | ||
cmd.Wait() | ||
} | ||
}() | ||
|
||
go func() { | ||
for scanner.Scan() { | ||
pth := scanner.Text() | ||
pth = filepath.Join(i.Path, pth) | ||
var info os.FileInfo | ||
if info, err = os.Stat(pth); err != nil { | ||
return | ||
} | ||
if err = cb(walker.FileInfo{FileInfo: info, Path: pth}); err != nil { | ||
return | ||
} | ||
} | ||
}() | ||
|
||
cmd.Wait() | ||
closed = true | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.