From 851a19bb607ed952656860a7ce3e7c1a4533572c Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 14 Nov 2014 17:31:16 +0800 Subject: [PATCH] ignore some VCS files when find --- file/files.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/file/files.go b/file/files.go index 878e244..b88a153 100644 --- a/file/files.go +++ b/file/files.go @@ -563,6 +563,9 @@ func renameFile(oldPath, newPath string) bool { return true } +// Default exclude file name patterns when find. +var defaultExcludesFind = []string{".git", ".svn", ".repository", "CVS", "RCS", "SCCS", ".bzr", ".metadata", ".hg"} + // find finds files under the specified dir and its sub-directoryies with the specified name, // likes the command 'find dir -name name'. func find(dir, name string, results []*string) []*string { @@ -581,9 +584,14 @@ func find(dir, name string, results []*string) []*string { } for _, fileInfo := range fileInfos { - path := dir + fileInfo.Name() + fname := fileInfo.Name() + path := dir + fname if fileInfo.IsDir() { + if util.Str.Contains(fname, defaultExcludesFind) { + continue + } + // enter the directory recursively results = find(path, name, results) } else {