MCPcopy Index your code
hub / github.com/drone-plugins/drone-github-release / writeChecksums

Function writeChecksums

utils.go:62–108  ·  view source on GitHub ↗
(files, methods []string, format string, flatten bool)

Source from the content-addressed store, hash-verified

60}
61
62func writeChecksums(files, methods []string, format string, flatten bool) ([]string, error) {
63 checksums := make(map[string][]string)
64
65 for _, method := range methods {
66 for _, file := range files {
67 handle, err := os.Open(file)
68
69 if err != nil {
70 return nil, fmt.Errorf("Failed to read %s artifact: %s", file, err)
71 }
72
73 hash, err := checksum(handle, method)
74
75 if err != nil {
76 return nil, err
77 }
78
79 checksums[method] = append(checksums[method], hash, file)
80 }
81 }
82
83 for method, results := range checksums {
84 filename := strings.Replace(format, "CHECKSUM", method, -1)
85 f, err := os.Create(filename)
86
87 if err != nil {
88 return nil, err
89 }
90
91 for i := 0; i < len(results); i += 2 {
92 hash := results[i]
93 file := results[i+1]
94
95 if flatten {
96 file = filepath.Base(file)
97 }
98
99 if _, err := f.WriteString(fmt.Sprintf("%s %s\n", hash, file)); err != nil {
100 return nil, err
101 }
102 }
103
104 files = append(files, filename)
105 }
106
107 return files, nil
108}

Callers 1

ExecMethod · 0.85

Calls 1

checksumFunction · 0.85

Tested by

no test coverage detected