summaryrefslogtreecommitdiffstats
path: root/recipes-devtools/go-dirhash-native/go-dirhash
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2025-12-04 22:18:41 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2025-12-08 20:57:44 -0500
commit44c4e44db7300f241e6740b389489e84ef7c1f65 (patch)
tree70bc0f53758513cd9d8f34f041d1de461125dbd7 /recipes-devtools/go-dirhash-native/go-dirhash
parent26e2b40b91f2424b0b9318b50dbb700a67714b6f (diff)
downloadmeta-virtualization-44c4e44db7300f241e6740b389489e84ef7c1f65.tar.gz
devtools: add go-dirhash-native for Go module hash calculation
Add a native recipe that builds the Go dirhash tool for calculating h1: hashes on module zip files. This is used as a fallback when the pure Python implementation cannot be used. The tool implements the Go module hash algorithm per the Go modules reference specification. Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'recipes-devtools/go-dirhash-native/go-dirhash')
-rw-r--r--recipes-devtools/go-dirhash-native/go-dirhash/LICENSE26
-rw-r--r--recipes-devtools/go-dirhash-native/go-dirhash/dirhash-helper.go24
2 files changed, 50 insertions, 0 deletions
diff --git a/recipes-devtools/go-dirhash-native/go-dirhash/LICENSE b/recipes-devtools/go-dirhash-native/go-dirhash/LICENSE
new file mode 100644
index 00000000..9feb7621
--- /dev/null
+++ b/recipes-devtools/go-dirhash-native/go-dirhash/LICENSE
@@ -0,0 +1,26 @@
1Copyright (c) 2009 The Go Authors. All rights reserved.
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in
10 the documentation and/or other materials provided with the
11 distribution.
12 * Neither the name of Google Inc. nor the names of its
13 contributors may be used to endorse or promote products derived
14 from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/recipes-devtools/go-dirhash-native/go-dirhash/dirhash-helper.go b/recipes-devtools/go-dirhash-native/go-dirhash/dirhash-helper.go
new file mode 100644
index 00000000..d2aec41c
--- /dev/null
+++ b/recipes-devtools/go-dirhash-native/go-dirhash/dirhash-helper.go
@@ -0,0 +1,24 @@
1package main
2
3import (
4 "fmt"
5 "os"
6
7 "golang.org/x/mod/sumdb/dirhash"
8)
9
10func main() {
11 if len(os.Args) != 2 {
12 fmt.Fprintf(os.Stderr, "Usage: %s <zip-file>\n", os.Args[0])
13 os.Exit(1)
14 }
15
16 zipPath := os.Args[1]
17 hash, err := dirhash.HashZip(zipPath, dirhash.DefaultHash)
18 if err != nil {
19 fmt.Fprintf(os.Stderr, "Error: %v\n", err)
20 os.Exit(1)
21 }
22
23 fmt.Println(hash)
24}