MCPcopy Index your code
hub / github.com/jetify-com/devbox / wipeProfileHistory

Function wipeProfileHistory

internal/devbox/nixprofile.go:103–127  ·  view source on GitHub ↗

wipeProfileHistory removes all old generations of a Nix profile, similar to nix profile wipe-history. profile should be a path to the "default" symlink, like .devbox/nix/profile/default.

(profile string)

Source from the content-addressed store, hash-verified

101// nix profile wipe-history. profile should be a path to the "default" symlink,
102// like .devbox/nix/profile/default.
103func wipeProfileHistory(profile string) error {
104 link, err := os.Readlink(profile)
105 if errors.Is(err, os.ErrNotExist) {
106 return nil
107 }
108 if err != nil {
109 return err
110 }
111
112 dir := filepath.Dir(profile)
113 entries, err := os.ReadDir(dir)
114 if err != nil {
115 return err
116 }
117 for _, dent := range entries {
118 if dent.Name() == "default" || dent.Name() == link {
119 continue
120 }
121 err := os.Remove(filepath.Join(dir, dent.Name()))
122 if err != nil && !errors.Is(err, os.ErrNotExist) {
123 return err
124 }
125 }
126 return nil
127}

Callers 1

Calls 3

ReadlinkMethod · 0.80
IsMethod · 0.80
RemoveMethod · 0.45

Tested by

no test coverage detected