Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfaa618a

Browse files
authored
fix: ignore some files to hash the version for custom build (#6100)
1 parent69cb39d commitfaa618a

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

‎pkg/commands/internal/builder.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (b Builder) createVersion(orig string) (string, error) {
257257
continue
258258
}
259259

260-
dh,err:=dirhash.HashDir(plugin.Path,"",dirhash.DefaultHash)
260+
dh,err:=hashDir(plugin.Path,"",dirhash.DefaultHash)
261261
iferr!=nil {
262262
return"",fmt.Errorf("hash plugin directory: %w",err)
263263
}

‎pkg/commands/internal/dirhash.go‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package internal
6+
7+
import (
8+
"fmt"
9+
"io"
10+
"os"
11+
"path/filepath"
12+
"strings"
13+
14+
"golang.org/x/mod/sumdb/dirhash"
15+
)
16+
17+
// Slightly modified copy of [dirhash.HashDir].
18+
// https://github.com/golang/mod/blob/v0.28.0/sumdb/dirhash/hash.go#L67-L79
19+
funchashDir(dir,prefixstring,hash dirhash.Hash) (string,error) {
20+
files,err:=dirFiles(dir,prefix)
21+
iferr!=nil {
22+
return"",err
23+
}
24+
25+
osOpen:=func(namestring) (io.ReadCloser,error) {
26+
returnos.Open(filepath.Join(dir,strings.TrimPrefix(name,prefix)))
27+
}
28+
29+
returnhash(files,osOpen)
30+
}
31+
32+
// Modified copy of [dirhash.DirFiles].
33+
// https://github.com/golang/mod/blob/v0.28.0/sumdb/dirhash/hash.go#L81-L109
34+
// And adapted to globally follows the rules from https://github.com/golang/mod/blob/v0.28.0/zip/zip.go
35+
funcdirFiles(dir,prefixstring) ([]string,error) {
36+
varfiles []string
37+
38+
dir=filepath.Clean(dir)
39+
40+
err:=filepath.Walk(dir,func(filestring,info os.FileInfo,errerror)error {
41+
iferr!=nil {
42+
returnerr
43+
}
44+
45+
ifinfo.IsDir() {
46+
ifdir==file {
47+
// Don't skip the top-level directory.
48+
returnnil
49+
}
50+
51+
switchinfo.Name() {
52+
// Skip vendor and node directories.
53+
case"vendor","node_modules":
54+
returnfilepath.SkipDir
55+
56+
// Skip VCS directories.
57+
case".bzr",".git",".hg",".svn":
58+
returnfilepath.SkipDir
59+
}
60+
61+
// Skip submodules (directories containing go.mod files).
62+
ifgoModInfo,err:=os.Lstat(filepath.Join(dir,"go.mod"));err==nil&&!goModInfo.IsDir() {
63+
returnfilepath.SkipDir
64+
}
65+
66+
returnnil
67+
}
68+
69+
iffile==dir {
70+
returnfmt.Errorf("%s is not a directory",dir)
71+
}
72+
73+
if!info.Mode().IsRegular() {
74+
returnnil
75+
}
76+
77+
rel:=file
78+
79+
ifdir!="." {
80+
rel=file[len(dir)+1:]
81+
}
82+
83+
f:=filepath.Join(prefix,rel)
84+
85+
files=append(files,filepath.ToSlash(f))
86+
87+
returnnil
88+
})
89+
iferr!=nil {
90+
returnnil,err
91+
}
92+
returnfiles,nil
93+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp