package modhost import ( "os" "path/filepath" "sync" "streamd/repo" ) var ( rootMu sync.RWMutex modulesDirOV string // absolute path override for the modules directory ) // SetModulesDir overrides where providers are discovered (streamd --modules-dir). // Empty clears the override. Relative paths are resolved against the process cwd. func SetModulesDir(dir string) error { rootMu.Lock() defer rootMu.Unlock() if dir == "" { modulesDirOV = "" return nil } abs, err := filepath.Abs(dir) if err != nil { return err } modulesDirOV = abs return nil } // ModulesDirOverride returns the --modules-dir override, or "". func ModulesDirOverride() string { rootMu.RLock() defer rootMu.RUnlock() return modulesDirOV } // EffectiveModulesDir is the directory that Discover/Open scan. // Prefer --modules-dir / STREAMD_MODULES_DIR / DRM_MODULES_DIR; else /modules. func EffectiveModulesDir(root string) string { if ov := ModulesDirOverride(); ov != "" { return ov } if root == "" { root = repo.Root() } return filepath.Join(root, "modules") } // ApplyEnvModulesDir sets the override from STREAMD_MODULES_DIR (preferred) or // DRM_MODULES_DIR when no flag was set. func ApplyEnvModulesDir() error { if ModulesDirOverride() != "" { return nil } v := os.Getenv("STREAMD_MODULES_DIR") if v == "" { v = os.Getenv("DRM_MODULES_DIR") } if v == "" { return nil } return SetModulesDir(v) }