MCPcopy
hub / github.com/dragonflyoss/dragonfly / CalculateSha256ByPersistentCacheTaskID

Function CalculateSha256ByPersistentCacheTaskID

test/e2e/util/task.go:76–102  ·  view source on GitHub ↗
(pods []*PodExec, taskID string)

Source from the content-addressed store, hash-verified

74}
75
76func 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
104func CalculateSha256ByOutput(pods []*PodExec, output string) (string, error) {
105 var sha256sum string

Callers 1

dfcache_test.goFile · 0.92

Calls 5

CommandMethod · 0.80
PrintlnMethod · 0.80
ErrorfMethod · 0.65
PrintfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected