(req dto.ContainerFileReq)
| 1383 | } |
| 1384 | |
| 1385 | func (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 | |
| 1417 | func (u *ContainerService) DownloadContainerFile(req dto.ContainerFileReq) (io.ReadCloser, string, string, error) { |
| 1418 | if len(req.Path) == 0 { |
nothing calls this directly
no test coverage detected