{"record":{"id":"cb73732c100164de","repo":"crowdsecurity/crowdsec","slug":"while-removing-symlink-w","errorCode":null,"errorMessage":"while removing symlink: %w","messagePattern":"while removing symlink: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hubops/disable.go","lineNumber":35,"sourceCode":"\t\treturn err\n\t}\n\n\t// if it's managed by hub, it's a symlink to csconfig.GConfig.hub.HubDir / ...\n\tif stat.Mode()&os.ModeSymlink == 0 {\n\t\treturn fmt.Errorf(\"%s isn't managed by hub\", i.Name)\n\t}\n\n\ttarget, err := os.Readlink(i.State.LocalPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while reading symlink: %w\", err)\n\t}\n\n\tif target != i.State.DownloadPath {\n\t\treturn fmt.Errorf(\"%s isn't managed by hub\", i.Name)\n\t}\n\n\tif err := os.Remove(i.State.LocalPath); err != nil {\n\t\treturn fmt.Errorf(\"while removing symlink: %w\", err)\n\t}\n\n\ti.State.LocalPath = \"\"\n\n\treturn nil\n}\n\n// DisableCommand uninstalls an item and its dependencies, ensuring that no\n// sub-item is left in an inconsistent state.\ntype DisableCommand struct {\n\tItem  *cwhub.Item\n\tForce bool\n}\n\nfunc NewDisableCommand(item *cwhub.Item, force bool) *DisableCommand {\n\treturn &DisableCommand{Item: item, Force: force}\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/hubops/disable.go#L17-L53","documentation":"Once the symlink is verified as hub-managed, RemoveInstallLink deletes it with os.Remove. If deletion fails, the error is wrapped as 'while removing symlink: %w' — typically a filesystem permission or I/O problem.","triggerScenarios":"Calling RemoveInstallLink when the containing directory is read-only or owned by another user, or the filesystem is full/errored.","commonSituations":"Running cscli as non-root against a root-owned config directory; read-only mounted configuration volume (containers); immutable files.","solutions":["Run the command with sufficient privileges (sudo/root)","Fix permissions/ownership of the config directory","Check whether the config volume is mounted read-only and remount read-write"],"exampleFix":"// before\ncscli parsers disable my-parser  # permission denied\n// after\nsudo cscli parsers disable my-parser","handlingStrategy":"try-catch","validationCode":"if err := unix.Access(filepath.Dir(item.State.LocalPath), unix.W_OK); err != nil { return fmt.Errorf(\"dir not writable: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err := hubops.RemoveInstallLink(item); err != nil {\n    if errors.Is(err, fs.ErrPermission) { /* advise sudo */ }\n    return err\n}","preventionTips":["Run cscli with the same user that owns the config directory","Avoid read-only mounts for the config directory in containers","Check writability of the config dir before hub mutations"],"tags":["hub","symlink","permission-denied"],"backgroundTag":"file-write-permission-denied","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"}