Sync replaces the watched set with paths. Files no longer in the list are removed; new files are added. Symlinks are resolved once. Individual arm failures are logged and skipped; partial arming is acceptable because parseAndDedup is the source of truth and the watcher exists purely to trigger a fre
(paths []string)
| 95 | // |
| 96 | // Sync is idempotent and safe to call repeatedly. |
| 97 | func (cw *configWatcher) Sync(paths []string) { |
| 98 | if cw == nil { |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | resolved := make(map[string]struct{}, len(paths)) |
| 103 | for _, p := range paths { |
| 104 | rp := resolvePath(p) |
| 105 | if rp == "" { |
| 106 | continue |
| 107 | } |
| 108 | resolved[rp] = struct{}{} |
| 109 | } |
| 110 | |
| 111 | cw.mu.Lock() |
| 112 | if cw.closed { |
| 113 | cw.mu.Unlock() |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | // Remove paths that are no longer wanted. |
| 118 | for rp, dir := range cw.files { |
| 119 | if _, keep := resolved[rp]; keep { |
| 120 | continue |
| 121 | } |
| 122 | delete(cw.files, rp) |
| 123 | cw.releaseDirLocked(dir) |
| 124 | } |
| 125 | |
| 126 | // Add new paths. |
| 127 | for rp := range resolved { |
| 128 | if _, already := cw.files[rp]; already { |
| 129 | continue |
| 130 | } |
| 131 | dir, err := cw.armAncestorLocked(rp) |
| 132 | if err != nil { |
| 133 | cw.logger.Warn(context.Background(), |
| 134 | "failed to arm config file watch", |
| 135 | slog.F("path", rp), slog.Error(err)) |
| 136 | continue |
| 137 | } |
| 138 | cw.files[rp] = dir |
| 139 | } |
| 140 | cw.mu.Unlock() |
| 141 | } |
| 142 | |
| 143 | // armAncestorLocked walks up the parent chain from rp until it |
| 144 | // finds an existing directory, then watches that directory. |