Skip to content

Commit

Permalink
testdriver: do not try to copy symlink files
Browse files Browse the repository at this point in the history
Also properly handle git-ignored files instead of maintaining a list of
our own in code.
  • Loading branch information
myitcv committed Jan 26, 2020
1 parent bb606ba commit 38e824d
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions testdriver/testdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,44 @@ func (d *TestDriver) LogStripANSI(r io.Reader) {
}

func copyDir(dst, src string) error {
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
switch path {
case filepath.Join(src, ".git"), filepath.Join(src, "cmd", "govim", ".bin"):
cmd := exec.Command("git", "status", "--ignored", "-uall", "--porcelain")
cmd.Dir = src
out, err := cmd.CombinedOutput()
if err != nil {
wd, _ := os.Getwd()
return fmt.Errorf("failed to determine ignored files in %v: %v\n%s", wd, err, out)
}
// ignored will contain ignored files relative to src
ignored := make(map[string]bool)
for _, l := range bytes.Split(out, []byte("\n")) {
l := string(l)
if !strings.HasPrefix(l, "!! ") {
continue
}
l = strings.TrimPrefix(l, "!! ")
ignored[l] = true
}
return filepath.Walk(src, func(path string, info os.FileInfo, ierr error) error {
if ierr != nil {
return ierr
}
if path == filepath.Join(src, ".git") {
return filepath.SkipDir
}
rel := strings.TrimPrefix(path, src)
if strings.HasPrefix(rel, string(os.PathSeparator)) {
rel = strings.TrimPrefix(rel, string(os.PathSeparator))
rel, err := filepath.Rel(src, path)
if err != nil {
return fmt.Errorf("failed to determine %v relative to %v: %v", path, src, err)
}
if ignored[rel] {
return nil
}
dstpath := filepath.Join(dst, rel)
if info.IsDir() {
return os.MkdirAll(dstpath, 0777)
}
if !info.Mode().IsRegular() {
return nil
}
return copyFile(dstpath, path)
})
}
Expand Down

0 comments on commit 38e824d

Please sign in to comment.