Skip to content

Commit 3841573

Browse files
committed
as per review
Signed-off-by: Andrew Thornton <[email protected]>
1 parent bfab646 commit 3841573

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

modules/options/base.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import (
99
"io/fs"
1010
"os"
1111
"path/filepath"
12+
13+
"code.gitea.io/gitea/modules/util"
1214
)
1315

1416
func walkAssetDir(root string, callback func(path, name string, d fs.DirEntry, err error) error) error {
1517
if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
18+
// name is the path relative to the root
1619
name := path[len(root):]
1720
if len(name) > 0 && name[0] == '/' {
1821
name = name[1:]
@@ -23,7 +26,7 @@ func walkAssetDir(root string, callback func(path, name string, d fs.DirEntry, e
2326
}
2427
return err
2528
}
26-
if d.Name() == ".DS_Store" && d.IsDir() { // Because Macs...
29+
if d.IsDir() && util.CommonSkipDir(d.Name()) {
2730
return fs.SkipDir
2831
}
2932
return callback(path, name, d, err)

modules/templates/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func walkAssetDir(root string, skipMail bool, callback func(path, name string, d
111111
if skipMail && path == mailRoot && d.IsDir() {
112112
return fs.SkipDir
113113
}
114-
if d.Name() == ".DS_Store" && d.IsDir() { // Because Macs...
114+
if d.IsDir() && util.CommonSkipDir(d.Name()) { // Because Macs...
115115
return fs.SkipDir
116116
}
117117
if strings.HasSuffix(d.Name(), ".tmpl") || d.IsDir() {

modules/templates/htmlrenderer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func HTMLRenderer(ctx context.Context) (context.Context, *render.Render) {
2121
rendererInterface := ctx.Value(rendererKey)
2222
if rendererInterface != nil {
2323
renderer, ok := rendererInterface.(*render.Render)
24-
if ok && renderer != nil {
24+
if ok {
2525
return ctx, renderer
2626
}
2727
}

modules/templates/mailer.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,7 @@ func Mailer(ctx context.Context) (*texttmpl.Template, *template.Template) {
4242
continue
4343
}
4444

45-
assetName := strings.TrimPrefix(
46-
strings.TrimSuffix(
47-
assetPath,
48-
".tmpl",
49-
),
50-
"mail/",
51-
)
45+
assetName := strings.TrimPrefix(strings.TrimSuffix(assetPath, ".tmpl"), "mail/")
5246

5347
log.Trace("Adding built-in mailer template for %s", assetName)
5448
buildSubjectBodyTemplate(subjectTemplates,

modules/util/path.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"path/filepath"
1313
"regexp"
1414
"runtime"
15-
"strings"
1615
)
1716

1817
// EnsureAbsolutePath ensure that a path is absolute, making it
@@ -91,7 +90,7 @@ func statDir(dirPath, recPath string, includeDir, isDirOnly, followSymlinks bool
9190

9291
statList := make([]string, 0)
9392
for _, fi := range fis {
94-
if strings.Contains(fi.Name(), ".DS_Store") {
93+
if fi.IsDir() && CommonSkipDir(fi.Name()) {
9594
continue
9695
}
9796

@@ -199,3 +198,9 @@ func HomeDir() (home string, err error) {
199198

200199
return home, nil
201200
}
201+
202+
// CommonSkipDir will check a provided name to see if it represents directory that should not be watched
203+
func CommonSkipDir(name string) bool {
204+
// Check for Mac's .DS_Store entries
205+
return name == ".DS_Store"
206+
}

modules/watcher/watcher.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ import (
1515
"github.com/fsnotify/fsnotify"
1616
)
1717

18+
// CreateWatcherOpts are options to configure the watcher
1819
type CreateWatcherOpts struct {
19-
PathsCallback func(func(path, name string, d fs.DirEntry, err error) error) error
20-
BeforeCallback func()
20+
// PathsCallback is used to set the required paths to watch
21+
PathsCallback func(func(path, name string, d fs.DirEntry, err error) error) error
22+
23+
// BeforeCallback is called before any files are watched
24+
BeforeCallback func()
25+
26+
// Between Callback is called between after a watched event has occured
2127
BetweenCallback func()
22-
AfterCallback func()
28+
29+
// AfterCallback is called as this watcher ends
30+
AfterCallback func()
2331
}
2432

33+
// CreateWatcher creates a watcher labelled with the provided description and running with the provided options.
34+
// The created watcher will create a subcontext from the provided ctx and register it with the process manager.
2535
func CreateWatcher(ctx context.Context, desc string, opts *CreateWatcherOpts) {
2636
go run(ctx, desc, opts)
2737
}
@@ -44,7 +54,7 @@ func run(ctx context.Context, desc string, opts *CreateWatcherOpts) {
4454
log.Error("Unable to create watcher for %s: %v", desc, err)
4555
return
4656
}
47-
if err := opts.PathsCallback(func(path, _ string, _ fs.DirEntry, err error) error {
57+
if err := opts.PathsCallback(func(path, _ string, d fs.DirEntry, err error) error {
4858
if err != nil && !os.IsNotExist(err) {
4959
return err
5060
}

0 commit comments

Comments
 (0)