MCPcopy
hub / github.com/autobrr/qui / Add

Method Add

internal/services/orphanscan/filemap.go:34–51  ·  view source on GitHub ↗

Add adds a normalized path to the map.

(path string)

Source from the content-addressed store, hash-verified

32
33// Add adds a normalized path to the map.
34func (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.
54func (m *TorrentFileMap) Has(path string) bool {

Calls 1

normalizePathFunction · 0.70