MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Delete

Method Delete

agent/app/service/runtime.go:285–324  ·  view source on GitHub ↗
(runtimeDelete request.RuntimeDelete)

Source from the content-addressed store, hash-verified

283}
284
285func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error {
286 runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(runtimeDelete.ID))
287 if err != nil {
288 return err
289 }
290 website, _ := websiteRepo.GetFirst(websiteRepo.WithRuntimeID(runtimeDelete.ID))
291 if website.ID > 0 {
292 return buserr.New("ErrDelWithWebsite")
293 }
294 if runtime.Resource != constant.ResourceAppstore {
295 return runtimeRepo.DeleteBy(repo.WithByID(runtimeDelete.ID))
296 }
297 projectDir := runtime.GetPath()
298 if out, err := compose.Down(runtime.GetComposePath()); err != nil && !runtimeDelete.ForceDelete {
299 if out != "" {
300 return errors.New(out)
301 }
302 return err
303 }
304 if runtime.Type == constant.RuntimePHP {
305 client, err := docker.NewClient()
306 if err != nil {
307 return err
308 }
309 defer client.Close()
310 imageID, err := client.GetImageIDByName(runtime.Image)
311 if err != nil {
312 return err
313 }
314 if imageID != "" {
315 if err := client.DeleteImage(imageID); err != nil {
316 global.LOG.Errorf("delete image id [%s] error %v", imageID, err)
317 }
318 }
319 }
320 if err := files.NewFileOp().DeleteDir(projectDir); err != nil && !runtimeDelete.ForceDelete {
321 return err
322 }
323 return runtimeRepo.DeleteBy(repo.WithByID(runtimeDelete.ID))
324}
325
326func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
327 runtime, err := runtimeRepo.GetFirst(context.Background(), repo.WithByID(id))

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
GetImageIDByNameMethod · 0.95
DeleteImageMethod · 0.95
DeleteDirMethod · 0.80
GetFirstMethod · 0.65
WithByIDMethod · 0.65
WithRuntimeIDMethod · 0.65
DeleteByMethod · 0.65
GetPathMethod · 0.45
GetComposePathMethod · 0.45

Tested by

no test coverage detected