| 74 | } |
| 75 | |
| 76 | func CalculateSha256ByPersistentCacheTaskID(pods []*PodExec, taskID string) (string, error) { |
| 77 | var sha256sum string |
| 78 | for _, pod := range pods { |
| 79 | contentPath := fmt.Sprintf("%s/persistent-cache-tasks/%s/%s", clientContentDir, taskID[:3], taskID) |
| 80 | if _, err := pod.Command("ls", contentPath).CombinedOutput(); err != nil { |
| 81 | // If the path does not exist, skip this client. |
| 82 | fmt.Printf("path %s does not exist: %s\n", contentPath, err.Error()) |
| 83 | continue |
| 84 | } |
| 85 | |
| 86 | // Calculate sha256sum of the task content. |
| 87 | out, err := pod.Command("sh", "-c", fmt.Sprintf("sha256sum %s", contentPath)).CombinedOutput() |
| 88 | if err != nil { |
| 89 | return "", fmt.Errorf("calculate sha256sum of %s failed: %s", contentPath, err.Error()) |
| 90 | } |
| 91 | |
| 92 | fmt.Println("sha256sum: " + string(out)) |
| 93 | sha256sum = strings.Split(string(out), " ")[0] |
| 94 | break |
| 95 | } |
| 96 | |
| 97 | if sha256sum == "" { |
| 98 | return "", errors.New("can not found sha256sum") |
| 99 | } |
| 100 | |
| 101 | return sha256sum, nil |
| 102 | } |
| 103 | |
| 104 | func CalculateSha256ByOutput(pods []*PodExec, output string) (string, error) { |
| 105 | var sha256sum string |