| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package entities
- import (
- "sync"
- "github.com/OliveTin/OliveTin/internal/filehelper"
- )
- var (
- loadAttemptedMu sync.RWMutex
- loadAttempted = map[string]bool{}
- )
- // MarkEntityLoadAttempted records that OliveTin has tried to load this entity
- // type from its entity file (successfully or not).
- func MarkEntityLoadAttempted(entityName string) {
- if entityName == "" {
- return
- }
- loadAttemptedMu.Lock()
- defer loadAttemptedMu.Unlock()
- loadAttempted[entityName] = true
- }
- // HasEntityLoadAttempted reports whether a load has been attempted for the entity type.
- func HasEntityLoadAttempted(entityName string) bool {
- loadAttemptedMu.RLock()
- defer loadAttemptedMu.RUnlock()
- return loadAttempted[entityName]
- }
- // ResetEntityLoadAttempts clears load-attempt tracking (used by tests).
- func ResetEntityLoadAttempts() {
- loadAttemptedMu.Lock()
- defer loadAttemptedMu.Unlock()
- loadAttempted = map[string]bool{}
- }
- // ResetEntityWatchersForTests clears watched-path tracking (used by tests).
- func ResetEntityWatchersForTests() {
- watchedMu.Lock()
- defer watchedMu.Unlock()
- for path := range watchedBindings {
- filehelper.StopFileWatch(path)
- }
- watchedBindings = map[string]entityWatchBinding{}
- }
- func watchedPathCountForTests() int {
- watchedMu.Lock()
- defer watchedMu.Unlock()
- return len(watchedBindings)
- }
|