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

Method GetContainerFileSize

agent/app/service/container.go:1385–1415  ·  view source on GitHub ↗
(req dto.ContainerFileReq)

Source from the content-addressed store, hash-verified

1383}
1384
1385func (u *ContainerService) GetContainerFileSize(req dto.ContainerFileReq) (int64, error) {
1386 if len(req.Path) == 0 {
1387 return 0, buserr.New("ErrInvalidChar")
1388 }
1389 cli, err := docker.NewDockerClient()
1390 if err != nil {
1391 return 0, err
1392 }
1393 defer cli.Close()
1394
1395 stat, err := cli.ContainerStatPath(context.Background(), req.ContainerID, req.Path)
1396 if err != nil {
1397 return 0, normalizeContainerFileError(err)
1398 }
1399 if !stat.Mode.IsDir() {
1400 return stat.Size, nil
1401 }
1402 output, err := runContainerCommand(cli, req.ContainerID, []string{"du", "-sb", "--", req.Path})
1403 if err != nil {
1404 return 0, err
1405 }
1406 parts := strings.Fields(output)
1407 if len(parts) == 0 {
1408 return 0, fmt.Errorf("invalid du output")
1409 }
1410 size, err := strconv.ParseInt(parts[0], 10, 64)
1411 if err != nil {
1412 return 0, err
1413 }
1414 return size, nil
1415}
1416
1417func (u *ContainerService) DownloadContainerFile(req dto.ContainerFileReq) (io.ReadCloser, string, string, error) {
1418 if len(req.Path) == 0 {

Callers

nothing calls this directly

Calls 4

runContainerCommandFunction · 0.85
IsDirMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected