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

Method loadPath

agent/app/service/container_compose.go:386–407  ·  view source on GitHub ↗
(req *dto.ComposeCreate)

Source from the content-addressed store, hash-verified

384}
385
386func (u *ContainerService) loadPath(req *dto.ComposeCreate) error {
387 if req.From == "template" || req.From == "edit" {
388 dir := fmt.Sprintf("%s/docker/compose/%s", global.Dir.DataDir, req.Name)
389 if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
390 if err = os.MkdirAll(dir, os.ModePerm); err != nil {
391 return err
392 }
393 }
394
395 path := fmt.Sprintf("%s/docker-compose.yml", dir)
396 file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, constant.FilePerm)
397 if err != nil {
398 return err
399 }
400 defer file.Close()
401 write := bufio.NewWriter(file)
402 _, _ = write.WriteString(string(req.File))
403 write.Flush()
404 req.Path = path
405 }
406 return nil
407}
408
409func removeContainerForCompose(composeName, composePath string) error {
410 if _, err := os.Stat(composePath); err == nil {

Callers 2

TestComposeMethod · 0.95
CreateComposeMethod · 0.95

Calls 5

MkdirAllMethod · 0.80
OpenFileMethod · 0.80
CloseMethod · 0.65
StatMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected