mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 04:40:52 +08:00
Revert watcher.go in "fix: enable hot reload for amp-model-mappings config"
This commit is contained in:
@@ -162,14 +162,12 @@ func NewWatcher(configPath, authDir string, reloadCallback func(*config.Config))
|
|||||||
|
|
||||||
// Start begins watching the configuration file and authentication directory
|
// Start begins watching the configuration file and authentication directory
|
||||||
func (w *Watcher) Start(ctx context.Context) error {
|
func (w *Watcher) Start(ctx context.Context) error {
|
||||||
// Watch the config file's parent directory instead of the file itself.
|
// Watch the config file
|
||||||
// This handles editors that use atomic save (write to temp, then rename).
|
if errAddConfig := w.watcher.Add(w.configPath); errAddConfig != nil {
|
||||||
configDir := filepath.Dir(w.configPath)
|
log.Errorf("failed to watch config file %s: %v", w.configPath, errAddConfig)
|
||||||
if errAddConfig := w.watcher.Add(configDir); errAddConfig != nil {
|
|
||||||
log.Errorf("failed to watch config directory %s: %v", configDir, errAddConfig)
|
|
||||||
return errAddConfig
|
return errAddConfig
|
||||||
}
|
}
|
||||||
log.Debugf("watching config directory: %s (for file: %s)", configDir, filepath.Base(w.configPath))
|
log.Debugf("watching config file: %s", w.configPath)
|
||||||
|
|
||||||
// Watch the auth directory
|
// Watch the auth directory
|
||||||
if errAddAuthDir := w.watcher.Add(w.authDir); errAddAuthDir != nil {
|
if errAddAuthDir := w.watcher.Add(w.authDir); errAddAuthDir != nil {
|
||||||
@@ -714,23 +712,7 @@ func (w *Watcher) isKnownAuthFile(path string) bool {
|
|||||||
func (w *Watcher) handleEvent(event fsnotify.Event) {
|
func (w *Watcher) handleEvent(event fsnotify.Event) {
|
||||||
// Filter only relevant events: config file or auth-dir JSON files.
|
// Filter only relevant events: config file or auth-dir JSON files.
|
||||||
configOps := fsnotify.Write | fsnotify.Create | fsnotify.Rename
|
configOps := fsnotify.Write | fsnotify.Create | fsnotify.Rename
|
||||||
// Check if this event is for our config file (handle both exact match and basename match for directory watching)
|
isConfigEvent := event.Name == w.configPath && event.Op&configOps != 0
|
||||||
isConfigEvent := false
|
|
||||||
if event.Op&configOps != 0 {
|
|
||||||
// Exact path match
|
|
||||||
if event.Name == w.configPath {
|
|
||||||
isConfigEvent = true
|
|
||||||
} else {
|
|
||||||
// Check if basename matches and it's in the config directory (for atomic save detection)
|
|
||||||
configDir := filepath.Dir(w.configPath)
|
|
||||||
configBase := filepath.Base(w.configPath)
|
|
||||||
eventDir := filepath.Dir(event.Name)
|
|
||||||
eventBase := filepath.Base(event.Name)
|
|
||||||
if eventDir == configDir && eventBase == configBase {
|
|
||||||
isConfigEvent = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
authOps := fsnotify.Create | fsnotify.Write | fsnotify.Remove | fsnotify.Rename
|
authOps := fsnotify.Create | fsnotify.Write | fsnotify.Remove | fsnotify.Rename
|
||||||
isAuthJSON := strings.HasPrefix(event.Name, w.authDir) && strings.HasSuffix(event.Name, ".json") && event.Op&authOps != 0
|
isAuthJSON := strings.HasPrefix(event.Name, w.authDir) && strings.HasSuffix(event.Name, ".json") && event.Op&authOps != 0
|
||||||
if !isConfigEvent && !isAuthJSON {
|
if !isConfigEvent && !isAuthJSON {
|
||||||
|
|||||||
Reference in New Issue
Block a user