Skip to content

Commit 12f1b38

Browse files
lunnyStelios Malathouras
authored and
Stelios Malathouras
committed
Don't store assets modified time into generated files (go-gitea#18193)
1 parent 2703dff commit 12f1b38

File tree

11 files changed

+110
-22
lines changed

11 files changed

+110
-22
lines changed

build/generate-bindata.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ func needsUpdate(dir string, filename string) (bool, []byte) {
5858
}
5959

6060
func main() {
61-
if len(os.Args) != 4 {
61+
if len(os.Args) < 4 {
6262
log.Fatal("Insufficient number of arguments. Need: directory packageName filename")
6363
}
6464

6565
dir, packageName, filename := os.Args[1], os.Args[2], os.Args[3]
66+
var useGlobalModTime bool
67+
if len(os.Args) == 5 {
68+
useGlobalModTime, _ = strconv.ParseBool(os.Args[4])
69+
}
6670

6771
update, newHash := needsUpdate(dir, filename)
6872

@@ -74,10 +78,11 @@ func main() {
7478
fmt.Printf("generating bindata for %s\n", packageName)
7579
var fsTemplates http.FileSystem = http.Dir(dir)
7680
err := vfsgen.Generate(fsTemplates, vfsgen.Options{
77-
PackageName: packageName,
78-
BuildTags: "bindata",
79-
VariableName: "Assets",
80-
Filename: filename,
81+
PackageName: packageName,
82+
BuildTags: "bindata",
83+
VariableName: "Assets",
84+
Filename: filename,
85+
UseGlobalModTime: useGlobalModTime,
8186
})
8287
if err != nil {
8388
log.Fatalf("%v\n", err)

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,5 @@ require (
141141
replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
142142

143143
replace github.com/golang-jwt/jwt v3.2.1+incompatible => github.com/golang-jwt/jwt v3.2.2+incompatible
144+
145+
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:uNwtsDp7
802802
github.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96/go.mod h1:mmIfjCSQlGYXmJ95jFN84AkQFnVABtKuJL8IrzwvUKQ=
803803
github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ=
804804
github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af/go.mod h1:Cqz6pqow14VObJ7peltM+2n3PWOz7yTrfUuGbVFkzN0=
805+
github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0 h1:F/3FfGmKdiKFa8kL3YrpZ7pe9H4l4AzA1pbaOUnRvPI=
806+
github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0/go.mod h1:JEfTc3+2DF9Z4PXhLLvXL42zexJyh8rIq3OzUj/0rAk=
805807
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
806808
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
807809
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@@ -1044,8 +1046,6 @@ github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR
10441046
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
10451047
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
10461048
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
1047-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=
1048-
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
10491049
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
10501050
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d/go.mod h1:vq0tzqLRu6TS7Id0wMo2N5QzJoKedVeovOpHjnykSzY=
10511051
github.com/siddontang/ledisdb v0.0.0-20190202134119-8ceb77e66a92/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=

modules/public/public_bindata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
package public
99

10-
//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../public public bindata.go
10+
//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../public public bindata.go true

modules/public/static.go

+6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ import (
1818
"time"
1919

2020
"code.gitea.io/gitea/modules/log"
21+
"code.gitea.io/gitea/modules/timeutil"
2122
)
2223

24+
// GlobalModTime provide a gloabl mod time for embedded asset files
25+
func GlobalModTime(filename string) time.Time {
26+
return timeutil.GetExecutableModTime()
27+
}
28+
2329
func fileSystem(dir string) http.FileSystem {
2430
return Assets
2531
}

modules/templates/static.go

+7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import (
1515
"path/filepath"
1616
"strings"
1717
texttmpl "text/template"
18+
"time"
1819

1920
"code.gitea.io/gitea/modules/log"
2021
"code.gitea.io/gitea/modules/setting"
22+
"code.gitea.io/gitea/modules/timeutil"
2123
"code.gitea.io/gitea/modules/util"
2224
)
2325

@@ -26,6 +28,11 @@ var (
2628
bodyTemplates = template.New("")
2729
)
2830

31+
// GlobalModTime provide a gloabl mod time for embedded asset files
32+
func GlobalModTime(filename string) time.Time {
33+
return timeutil.GetExecutableModTime()
34+
}
35+
2936
// GetAsset get a special asset, only for chi
3037
func GetAsset(name string) ([]byte, error) {
3138
bs, err := os.ReadFile(filepath.Join(setting.CustomPath, name))

modules/templates/templates_bindata.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
package templates
99

10-
//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../templates templates bindata.go
10+
//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../templates templates bindata.go true

modules/timeutil/executable.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package timeutil
6+
7+
import (
8+
"os"
9+
"path/filepath"
10+
"sync"
11+
"time"
12+
13+
"code.gitea.io/gitea/modules/log"
14+
)
15+
16+
var executablModTime = time.Now()
17+
var executablModTimeOnce sync.Once
18+
19+
// GetExecutableModTime get executable file modified time of current process.
20+
func GetExecutableModTime() time.Time {
21+
executablModTimeOnce.Do(func() {
22+
exePath, err := os.Executable()
23+
if err != nil {
24+
log.Error("os.Executable: %v", err)
25+
return
26+
}
27+
28+
exePath, err = filepath.Abs(exePath)
29+
if err != nil {
30+
log.Error("filepath.Abs: %v", err)
31+
return
32+
}
33+
34+
exePath, err = filepath.EvalSymlinks(exePath)
35+
if err != nil {
36+
log.Error("filepath.EvalSymlinks: %v", err)
37+
return
38+
}
39+
40+
st, err := os.Stat(exePath)
41+
if err != nil {
42+
log.Error("os.Stat: %v", err)
43+
return
44+
}
45+
46+
executablModTime = st.ModTime()
47+
})
48+
return executablModTime
49+
}

vendor/github.com/shurcooL/vfsgen/generator.go

+26-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/shurcooL/vfsgen/options.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ github.com/sergi/go-diff/diffmatchpatch
727727
# github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
728728
## explicit
729729
github.com/shurcooL/httpfs/vfsutil
730-
# github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
730+
# github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
731731
## explicit
732732
github.com/shurcooL/vfsgen
733733
# github.com/sirupsen/logrus v1.8.1
@@ -1061,3 +1061,4 @@ xorm.io/xorm/schemas
10611061
xorm.io/xorm/tags
10621062
# github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
10631063
# github.com/golang-jwt/jwt v3.2.1+incompatible => github.com/golang-jwt/jwt v3.2.2+incompatible
1064+
# github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0

0 commit comments

Comments
 (0)