This commit is contained in:
Liang Ding 2014-10-11 15:29:21 +08:00
parent 0cf675ce5b
commit b63c661433
2 changed files with 13 additions and 20 deletions

View File

@ -15,21 +15,9 @@
"Password": "admin", "Password": "admin",
"Workspace": "{pwd}/data/user_workspaces/admin", "Workspace": "{pwd}/data/user_workspaces/admin",
"LatestSessionContent": { "LatestSessionContent": {
"FileTree": [ "FileTree": [],
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest", "Files": [],
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello", "CurrentFile": ""
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time",
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\pkg",
"D:\\go\\src\\pkg",
"D:\\go\\src\\pkg\\archive",
"D:\\go\\src\\pkg\\archive\\tar",
"D:\\go\\src\\pkg\\archive\\tar\\testdata"
],
"Files": [
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\hello\\main.go",
"E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go"
],
"CurrentFile": "E:\\Work\\go\\src\\github.com\\b3log\\wide\\data\\user_workspaces\\admin\\src\\mytest\\time\\main.go"
} }
} }
] ]

View File

@ -423,6 +423,10 @@ func removeFile(path string) bool {
// 在 dir 指定的目录(包含子目录)中的 extension 指定后缀的文件中搜索包含 text 文本的文件,类似 grep/findstr 命令. // 在 dir 指定的目录(包含子目录)中的 extension 指定后缀的文件中搜索包含 text 文本的文件,类似 grep/findstr 命令.
func search(dir, extension, text string, snippets []*Snippet) []*Snippet { func search(dir, extension, text string, snippets []*Snippet) []*Snippet {
if !strings.HasSuffix(dir, string(os.PathSeparator)) {
dir += string(os.PathSeparator)
}
f, _ := os.Open(dir) f, _ := os.Open(dir)
fileInfos, err := f.Readdir(-1) fileInfos, err := f.Readdir(-1)
f.Close() f.Close()
@ -434,12 +438,13 @@ func search(dir, extension, text string, snippets []*Snippet) []*Snippet {
} }
for _, fileInfo := range fileInfos { for _, fileInfo := range fileInfos {
name := fileInfo.Name() path := dir + fileInfo.Name()
path := dir + name
if fileInfo.IsDir() { // 进入目录递归 if fileInfo.IsDir() {
search(path, extension, text, snippets) // 进入目录递归
} else if strings.HasSuffix(name, extension) { // 在文件中进行搜索 snippets = search(path, extension, text, snippets)
} else if strings.HasSuffix(path, extension) {
// 在文件中进行搜索
ss := searchInFile(path, text) ss := searchInFile(path, text)
snippets = append(snippets, ss...) snippets = append(snippets, ss...)