{"record":{"id":"024b1d4d6563322e","repo":"gastownhall/beads","slug":"clearing-remote-store-s-w","errorCode":null,"errorMessage":"clearing remote store %s: %w","messagePattern":"clearing remote store (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/dolt_remote_reset_data.go","lineNumber":182,"sourceCode":"\tfor _, e := range base {\n\t\tif !strings.HasPrefix(e, prefix) {\n\t\t\tenv = append(env, e)\n\t\t}\n\t}\n\treturn append(env, prefix+merged)\n}\n\n// clearDoltFileStore removes the contents of a native Dolt file-store\n// directory, keeping the directory itself so the follow-up push can rebuild\n// the store in place. The caller has already verified a manifest is present.\nfunc clearDoltFileStore(dir string) error {\n\tentries, err := os.ReadDir(dir)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading remote store %s: %w\", dir, err)\n\t}\n\tfor _, entry := range entries {\n\t\tif err := os.RemoveAll(filepath.Join(dir, entry.Name())); err != nil {\n\t\t\treturn fmt.Errorf(\"clearing remote store %s: %w\", dir, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nvar doltRemoteResetDataYes bool\n\nvar doltRemoteResetDataCmd = &cobra.Command{\n\tUse:   \"reset-data <name>\",\n\tShort: \"Replace a remote's data plane in place after a history squash\",\n\tLong: `Replace a Dolt remote's stored data with a fresh copy of local HEAD.\n\nAfter a history squash (see the History Bloat recovery runbook), a plain\n'bd dolt push --force' re-points the remote's refs but deletes nothing:\nDolt remotes accumulate chunks monotonically, so the remote keeps the full\npre-squash store. This command rebuilds the remote's data plane so it holds\nonly live chunks:\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/dolt_remote_reset_data.go#L164-L200","documentation":"Wraps an os.RemoveAll failure while emptying the directory that backs a Dolt remote store during 'bd dolt-remote reset-data'. Before resetting, clearDoltFileStore deletes every entry in the remote store directory; if the OS refuses to remove any entry (permissions, file in use, read-only mount), the underlying error is wrapped with the directory path. This aborts the reset so the caller never ends up with a partially reset remote that looks clean.","triggerScenarios":"Running a reset-data command when an entry under the remote store dir cannot be removed: files owned by another user/root, a running dolt server holding open files on some filesystems, a read-only or full-disk mount, or NFS stale handles.","commonSituations":"Running bd as a non-root user against a root-owned .beads/dolt remote dir; resetting while a background dolt server or another bd process has the store open; containers with read-only volume mounts; SELinux/AppArmor denials.","solutions":["Stop any running dolt server / bd daemon holding files open, then re-run the reset","Check and fix permissions on the remote store directory (chown/chmod, or run with adequate privileges)","Verify the mount is writable (not read-only, disk not full): df -h and mount flags","Remove the directory contents manually with rm -rf, then retry the reset"],"exampleFix":"// before\n$ bd dolt-remote reset-data origin\nError: clearing remote store /repo/.beads/dolt: permission denied\n// after\n$ chown -R $(whoami) /repo/.beads/dolt\n$ bd dolt-remote reset-data origin","handlingStrategy":"validation","validationCode":"info, err := os.Stat(remoteDir)\nif err != nil { return err }\nif info.Mode()&0200 == 0 { return fmt.Errorf(\"remote store %s not writable\", remoteDir) }\nprobe := filepath.Join(remoteDir, \".bd-write-test\")\nif err := os.WriteFile(probe, nil, 0o644); err != nil { return err }\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run bd as a user with write access to the .beads/dolt directory","Stop dolt servers/daemons before reset-data","Keep remote store mounts read-write and with free disk space"],"tags":["filesystem","permissions","dolt","reset"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}