| 384 | } |
| 385 | |
| 386 | func (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 | |
| 409 | func removeContainerForCompose(composeName, composePath string) error { |
| 410 | if _, err := os.Stat(composePath); err == nil { |