MCPcopy Create free account
hub / github.com/celer-pkg/celer / cleanAll

Method cleanAll

cmds/cmd_clean.go:186–241  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

184}
185
186func (c *cleanCmd) cleanAll() error {
187 if !fileio.PathExists(dirs.BuildtreesDir) {
188 return nil
189 }
190
191 var cleaned bool
192 entities, err := os.ReadDir(dirs.BuildtreesDir)
193 if err != nil {
194 return err
195 }
196
197 for _, entity := range entities {
198 cleaned = false
199 nameVersion := entity.Name()
200 buildDir := filepath.Join(dirs.BuildtreesDir, entity.Name())
201 entities, err := os.ReadDir(buildDir)
202 if err != nil {
203 return err
204 }
205
206 leaveLoop: // Remove all except src.
207 for _, entity := range entities {
208 // Remove build dir and log files.
209 if entity.Name() != "src" {
210 if err := os.RemoveAll(filepath.Join(buildDir, entity.Name())); err != nil {
211 return err
212 }
213 }
214
215 // Clean repo.
216 var port configs.Port
217 if err := port.Init(c.celer, nameVersion); err != nil {
218 if errors.Is(err, errors.ErrPortNotFound) {
219 color.Printf(color.Warning, "\n[clean %s]: cannot find it in ports, clean is skipped.\n", port.NameVersion())
220 break leaveLoop
221 }
222 return err
223 }
224 if err := port.MatchedConfig.Clean(); err != nil {
225 // Do not clean non-git repo.
226 if errors.Is(errors.ErrNotGitDir, err) {
227 return nil
228 }
229 return err
230 }
231 cleaned = true
232 }
233
234 if cleaned {
235 color.Printf(color.Hint, "✔ %s\n", entity.Name())
236 }
237 }
238
239 color.PrintSuccess("all packages cleaned.")
240 return nil
241}
242
243func (c *cleanCmd) doClean(port configs.Port) error {

Calls 8

InitMethod · 0.95
NameVersionMethod · 0.95
PathExistsFunction · 0.92
IsFunction · 0.92
PrintfFunction · 0.92
PrintSuccessFunction · 0.92
NameMethod · 0.65
CleanMethod · 0.65