{"record":{"id":"47db6a252eb60ab6","repo":"crowdsecurity/crowdsec","slug":"s-is-already-installed-at-s","errorCode":null,"errorMessage":"%s is already installed at %s","messagePattern":"(.+?) is already installed at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/cwhub/item.go","lineNumber":123,"sourceCode":"\tDescription string   `json:\"description,omitempty\" yaml:\"description,omitempty\"`\n\tContent     string   `json:\"content,omitempty\"     yaml:\"-\"`\n\tReferences  []string `json:\"references,omitempty\"  yaml:\"references,omitempty\"`\n\n\t// NOTE: RemotePath could be derived from the other fields\n\tRemotePath string                 `json:\"path,omitempty\"     yaml:\"path,omitempty\"`    // path relative to the base URL eg. /parsers/stage/author/file.yaml\n\tVersion    string                 `json:\"version,omitempty\"  yaml:\"version,omitempty\"` // the last available version\n\tVersions   map[string]ItemVersion `json:\"versions,omitempty\" yaml:\"-\"`                 // all the known versions\n\n\t// The index contains the dependencies of the \"latest\" version (collections only)\n\tDependencies\n}\n\n// PathForInstall returns the path to use for the install symlink\n// (eg. /etc/crowdsec/collections/xyz.yaml).\n// Returns an error if an item is already installed or if the path goes outside of the install dir.\nfunc (i *Item) PathForInstall() (string, error) {\n\tif i.State.IsInstalled() {\n\t\treturn \"\", fmt.Errorf(\"%s is already installed at %s\", i.FQName(), i.State.LocalPath)\n\t}\n\n\tp := i.Type\n\tif i.Stage != \"\" {\n\t\tp = filepath.Join(p, i.Stage)\n\t}\n\n\treturn SafePath(i.hub.local.InstallDir, filepath.Join(p, i.FileName))\n}\n\n// PathForDownload returns the path to use to store the item's file from the hub\n// (eg. /etc/crowdsec/hub/collections/author/xyz.yaml).\n// Raises an error if the path goes outside of the hub dir.\nfunc (i *Item) PathForDownload() (string, error) {\n\tpath, err := SafePath(i.hub.local.HubDir, i.RemotePath)\n\n\tif i.State.IsDownloaded() && path != i.State.DownloadPath {\n\t\t// A hub item with the same name is at a different location.","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/item.go#L105-L141","documentation":"Item.PathForInstall computes the symlink target for installing an item. If i.State.IsInstalled() is true, the item already has a local symlink, and reinstalling would overwrite/conflict, so it errors instead.","triggerScenarios":"Calling CreateInstallLink / PathForInstall on an item whose State shows an existing local installation (LocalPath set and installed flag true).","commonSituations":"Running `cscli hub install` twice without --force; scripted installs that don't check installed state first; a leftover symlink from a previous install making the item look installed.","solutions":["Skip the install if the item is already installed (check i.State.IsInstalled() first)","Use `cscli collections install <name> --force` (or the corresponding upgrade path) to overwrite","Remove the existing symlink at State.LocalPath before installing","Use item.Upgrade instead of Install when intending to refresh"],"exampleFix":"// before\npath, err := item.PathForInstall()\n// after\nif !item.State.IsInstalled() {\n    path, err := item.PathForInstall()\n    ...\n}","handlingStrategy":"validation","validationCode":"if item.State.IsInstalled() {\n    return nil // or item.Upgrade()\n}","typeGuard":null,"tryCatchPattern":"if err := item.PathForInstall(); err != nil {\n    if item.State.IsInstalled() {\n        // already installed: skip or upgrade\n        return nil\n    }\n    return err\n}","preventionTips":["Check State.IsInstalled() before every install call","Use upgrade paths instead of repeated installs","Clean up orphaned symlinks in the install dir"],"tags":["hub","install","symlink"],"backgroundTag":"file-already-exists","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}