MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / NewWatcher

Function NewWatcher

internal/watcher/watcher.go:93–120  ·  view source on GitHub ↗

NewWatcher creates a new file watcher instance

(configPath, authDir string, reloadCallback func(*config.Config))

Source from the content-addressed store, hash-verified

91
92// NewWatcher creates a new file watcher instance
93func NewWatcher(configPath, authDir string, reloadCallback func(*config.Config)) (*Watcher, error) {
94 watcher, errNewWatcher := fsnotify.NewWatcher()
95 if errNewWatcher != nil {
96 return nil, errNewWatcher
97 }
98 w := &Watcher{
99 configPath: configPath,
100 authDir: authDir,
101 reloadCallback: reloadCallback,
102 watcher: watcher,
103 lastAuthHashes: make(map[string]string),
104 fileAuthsByPath: make(map[string]map[string]*coreauth.Auth),
105 }
106 w.dispatchCond = sync.NewCond(&w.dispatchMu)
107 if store := sdkAuth.GetTokenStore(); store != nil {
108 if persister, ok := store.(storePersister); ok {
109 w.storePersister = persister
110 log.Debug("persistence-capable token store detected; watcher will propagate persisted changes")
111 }
112 if provider, ok := store.(authDirProvider); ok {
113 if fixed := strings.TrimSpace(provider.AuthDir()); fixed != "" {
114 w.mirroredAuthDir = fixed
115 log.Debugf("mirrored auth directory locked to %s", fixed)
116 }
117 }
118 }
119 return w, nil
120}
121
122// Start begins watching the configuration file and authentication directory
123func (w *Watcher) Start(ctx context.Context) error {

Calls 1

AuthDirMethod · 0.65