Add adds a normalized path to the map.
(path string)
| 32 | |
| 33 | // Add adds a normalized path to the map. |
| 34 | func (m *TorrentFileMap) Add(path string) { |
| 35 | n := normalizePath(path) |
| 36 | // Track the file itself. |
| 37 | m.mu.Lock() |
| 38 | m.paths[n] = struct{}{} |
| 39 | // Track all ancestor directories so we can quickly answer "is any torrent file under this dir?". |
| 40 | // This keeps lookup O(1) and avoids expensive prefix scans. |
| 41 | dir := filepath.Dir(n) |
| 42 | for dir != "." && dir != string(filepath.Separator) { |
| 43 | m.dirs[dir] = struct{}{} |
| 44 | parent := filepath.Dir(dir) |
| 45 | if parent == dir { |
| 46 | break |
| 47 | } |
| 48 | dir = parent |
| 49 | } |
| 50 | m.mu.Unlock() |
| 51 | } |
| 52 | |
| 53 | // Has checks if a normalized path exists in the map. |
| 54 | func (m *TorrentFileMap) Has(path string) bool { |