Skip to content

Commit

Permalink
fix(watch): Options.MainFiles 以非文件名结尾时可以正确获得工作目录
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Sep 12, 2023
1 parent 9037088 commit 0d1ca35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions watch/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ func (opt *Options) sanitize() (err error) {
}

// 根据 MainFiles 拿到 wd 和 appName
if last := opt.MainFiles[len(opt.MainFiles)-1]; last != '.' && last != '/' {
opt.wd = filepath.Dir(opt.MainFiles)

// MainFiles 可能是 *.go 等非正常的目录结构,根据最后一个字符作简单判断。
opt.wd = opt.MainFiles
if last := opt.wd[len(opt.wd)-1]; last != '.' && last != '/' {
opt.wd = filepath.Dir(opt.wd)
}
opt.wd, err = filepath.Abs(opt.wd)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion watch/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestRecursivePath(t *testing.T) {
abs := func(s string) string {
ss, err := filepath.Abs(s)
a.NotError(err).NotEmpty(ss)
return ss
return filepath.ToSlash(ss)
}

paths, err := recursivePaths("./testdir/testdir1")
Expand Down

0 comments on commit 0d1ca35

Please sign in to comment.