{"record":{"id":"dae09117d8636efe","repo":"thanos-io/thanos","slug":"remove-s","errorCode":null,"errorMessage":"remove %s","messagePattern":"remove (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rules/manager.go","lineNumber":336,"sourceCode":"}\n\n// Update updates rules from given files to all managers we hold. We decide which groups should go where, based on\n// special field in configGroups.configRuleAdapter struct.\nfunc (m *Manager) Update(evalInterval time.Duration, files []string) error {\n\tvar (\n\t\terrs            errutil.MultiError\n\t\tfilesByStrategy = map[storepb.PartialResponseStrategy][]string{}\n\t\truleFiles       = map[string]string{}\n\t)\n\n\t// Initialize filesByStrategy for existing managers' strategies to make\n\t// sure that managers are updated when they have no rules configured.\n\tfor strategy := range m.mgrs {\n\t\tfilesByStrategy[strategy] = make([]string, 0)\n\t}\n\n\tif err := os.RemoveAll(m.workDir); err != nil {\n\t\treturn errors.Wrapf(err, \"remove %s\", m.workDir)\n\t}\n\tif err := os.MkdirAll(m.workDir, os.ModePerm); err != nil {\n\t\treturn errors.Wrapf(err, \"create %s\", m.workDir)\n\t}\n\n\tfor _, fn := range files {\n\t\tb, err := os.ReadFile(filepath.Clean(fn))\n\t\tif err != nil {\n\t\t\terrs.Add(err)\n\t\t\tcontinue\n\t\t}\n\n\t\tvar rg configGroups\n\t\tif err := yaml.Unmarshal(b, &rg); err != nil {\n\t\t\terrs.Add(errors.Wrap(err, fn))\n\t\t\tcontinue\n\t\t}\n","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/rules/manager.go#L318-L354","documentation":"Manager.Update rewrites the rule files directory: it first removes the entire workDir with os.RemoveAll. If removal fails (permissions, busy files, or being inside the directory), the error is wrapped as \"remove %s\" and the update aborts.","triggerScenarios":"os.RemoveAll(m.workDir) returns an error: workDir or a child is not writable/deletable by the process user, workDir is a mount point, or a file is held open on Windows.","commonSituations":"Running Thanos as non-root while workDir was created by root; workDir on a read-only volume or immutable mount; stale permissions after container restart; workDir nested under a bind mount.","solutions":["Check and fix ownership/permissions of workDir (chown/chmod) for the process user","Ensure workDir is not a mount point or on a read-only filesystem","Set --rules-dir (workDir) to a dedicated writable path like /var/lib/thanos/rules","Stop processes holding files open in workDir, then retry the update"],"exampleFix":"// before\nthanos rule --rules-dir /etc/thanos   # root-owned, process runs as nobody\n// after\nmkdir -p /var/lib/thanos/rules && chown nobody: /var/lib/thanos/rules\nthanos rule --rules-dir /var/lib/thanos/rules","handlingStrategy":"validation","validationCode":"info, err := os.Stat(workDir)\nif err == nil {\n    test := filepath.Join(workDir, \".writable\")\n    if err := os.WriteFile(test, nil, 0o644); err != nil {\n        return fmt.Errorf(\"workDir %s not writable: %w\", workDir, err)\n    }\n    os.Remove(test)\n}","typeGuard":"func canRemoveAll(dir string) bool {\n    parent := filepath.Dir(dir)\n    f, err := os.Open(parent)\n    if err != nil { return false }\n    defer f.Close()\n    _, err = f.Readdirnames(1)\n    return err == nil\n}","tryCatchPattern":"if err := os.RemoveAll(m.workDir); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, syscall.EACCES) {\n        // fix permissions or fall back to per-file deletion\n    }\n    return errors.Wrapf(err, \"remove %s\", m.workDir)\n}","preventionTips":["Run the process as a user that owns the rules dir","Never place workDir on read-only or mount-point paths","Pre-provision the dir with correct ownership at deploy time"],"tags":["filesystem","permissions","rules-manager"],"backgroundTag":"file-remove-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}