{"record":{"id":"f138febdc6591de7","repo":"crowdsecurity/crowdsec","slug":"s-is-already-downloaded-at-s","errorCode":null,"errorMessage":"%s is already downloaded at %s","messagePattern":"(.+?) is already downloaded at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cwhub/item.go","lineNumber":145,"sourceCode":"\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.\n\t\t// This should not happen.\n\t\t// user is downloading with --force so we are allowed to overwrite but\n\t\t// should we remove the old location from here? Error, warning, more tests?\n\t\treturn \"\", fmt.Errorf(\"%s is already downloaded at %s\", i.FQName(), i.State.DownloadPath)\n\t}\n\n\treturn path, err\n}\n\n// HasSubItems returns true if items of this type can have sub-items. Currently only collections.\nfunc (i *Item) HasSubItems() bool {\n\treturn i.Type == COLLECTIONS\n}\n\n// MarshalJSON is used to prepare the output for \"cscli ... inspect -o json\".\n// It must not use a pointer receiver.\nfunc (i Item) MarshalJSON() ([]byte, error) {\n\ttype Alias Item\n\n\treturn json.Marshal(&struct {\n\t\tAlias\n\t\t// we have to repeat the fields here, json will have inline support in v2","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/cwhub/item.go#L127-L163","documentation":"Item.PathForDownload computes where an item should be downloaded. If the item is already downloaded but the newly computed path differs from the recorded State.DownloadPath, the same-named item lives in two locations — an inconsistent state the library refuses to guess about, returning an error.","triggerScenarios":"Downloading (even with --force) an item whose State.DownloadPath points somewhere else than the path derived from the current hub configuration — e.g. the install dir or item type mapping changed between runs.","commonSituations":"Moving or renaming the hub/install directories in config after items were downloaded; changing item type/stage so the computed path shifts; corrupted State from manual file moves.","solutions":["Remove the stale file at i.State.DownloadPath (or `cscli hub remove` the item) and re-download","Re-align config so install/hub dirs match where items were originally downloaded","Reset hub state by re-running `cscli hub update` and reinstalling affected items","If intentional, clear the item's State before calling PathForDownload"],"exampleFix":"// before\npath, err := item.PathForDownload(downloadDir) // errors: different location\n// after\nos.Remove(item.State.DownloadPath) // clean stale copy first\npath, err := item.PathForDownload(downloadDir)","handlingStrategy":"try-catch","validationCode":"if item.State.IsDownloaded() {\n    expected, _ := item.PathForDownload(dir) // may error; compare first\n    _ = expected\n}","typeGuard":null,"tryCatchPattern":"path, err := item.PathForDownload(dir)\nif err != nil && strings.Contains(err.Error(), \"already downloaded\") {\n    os.Remove(item.State.DownloadPath)\n    path, err = item.PathForDownload(dir)\n}","preventionTips":["Don't change hub/install directory config after items are installed","Keep item type/stage metadata consistent with on-disk layout","Reinstall items after moving crowdsec config directories"],"tags":["hub","download","state"],"backgroundTag":"conflicting-config-options","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"}