Skip to content

Commit

Permalink
cleaner support dirx
Browse files Browse the repository at this point in the history
  • Loading branch information
redHJ committed Feb 5, 2020
1 parent 86ba0b9 commit 69d4207
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cleaner/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"path/filepath"
"time"

"github.com/bmatcuk/doublestar"

"github.com/qiniu/log"

"github.com/qiniu/logkit/conf"
Expand Down Expand Up @@ -143,7 +145,7 @@ func (c *Cleaner) checkBelong(path string) bool {
return matched

case config.ModeDirx:
matched, err := filepath.Match(c.logdir, filepath.Dir(path))
matched, err := doublestar.Match(c.logdir, filepath.Dir(path))
if err != nil {
log.Errorf("Failed to check if %q belongs to %q: %v", path, c.logdir, err)
return false
Expand Down
18 changes: 16 additions & 2 deletions mgr/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

"github.com/bmatcuk/doublestar"
"github.com/fsnotify/fsnotify"
"github.com/json-iterator/go"

Expand Down Expand Up @@ -448,8 +449,9 @@ func (m *Manager) handle(path string, watcher *fsnotify.Watcher) {
}

func (m *Manager) getCleanQueues(dir, file, mode string) ([]*cleanQueue, error) {
if mode == ModeTailx {
cleanQueues := make([]*cleanQueue, 0, len(m.cleanQueues))
cleanQueues := make([]*cleanQueue, 0, len(m.cleanQueues))
switch mode {
case ModeTailx:
for k, v := range m.cleanQueues {
matched, err := filepath.Match(k, filepath.Join(dir, file))
if err != nil {
Expand All @@ -461,6 +463,18 @@ func (m *Manager) getCleanQueues(dir, file, mode string) ([]*cleanQueue, error)
}
}
return cleanQueues, nil
case ModeDirx:
for k, v := range m.cleanQueues {
matched, err := doublestar.Match(k, dir)
if err != nil {
log.Errorf("match pattern[%v] to path(%v) err %v", k, filepath.Join(dir, file), err)
continue
}
if matched {
cleanQueues = append(cleanQueues, v)
}
}
return cleanQueues, nil
}

q, ok := m.cleanQueues[dir]
Expand Down

0 comments on commit 69d4207

Please sign in to comment.