diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-01-07 10:33:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 21:33:17 -0500 |
commit | a1c12fb0b3a88e21e4c8c8f29c13e63cf4bc38dd (patch) | |
tree | 7add88555600d96deecbc9f97217d183f83f3edc /modules | |
parent | 21ed4fd8da4c8992518dcfb01aa7306f7406f735 (diff) | |
download | gitea-a1c12fb0b3a88e21e4c8c8f29c13e63cf4bc38dd.tar.gz gitea-a1c12fb0b3a88e21e4c8c8f29c13e63cf4bc38dd.zip |
Don't store assets modified time into generated files (#18193)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/public/public_bindata.go | 2 | ||||
-rw-r--r-- | modules/public/static.go | 6 | ||||
-rw-r--r-- | modules/templates/static.go | 7 | ||||
-rw-r--r-- | modules/templates/templates_bindata.go | 2 | ||||
-rw-r--r-- | modules/timeutil/executable.go | 49 |
5 files changed, 64 insertions, 2 deletions
diff --git a/modules/public/public_bindata.go b/modules/public/public_bindata.go index eb10d96426..c5485b7cc0 100644 --- a/modules/public/public_bindata.go +++ b/modules/public/public_bindata.go @@ -7,4 +7,4 @@ package public -//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../public public bindata.go +//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../public public bindata.go true diff --git a/modules/public/static.go b/modules/public/static.go index 32ba0fe258..2e35329a07 100644 --- a/modules/public/static.go +++ b/modules/public/static.go @@ -18,8 +18,14 @@ import ( "time" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/timeutil" ) +// GlobalModTime provide a gloabl mod time for embedded asset files +func GlobalModTime(filename string) time.Time { + return timeutil.GetExecutableModTime() +} + func fileSystem(dir string) http.FileSystem { return Assets } diff --git a/modules/templates/static.go b/modules/templates/static.go index fdd68c1e6a..c2295b2bd8 100644 --- a/modules/templates/static.go +++ b/modules/templates/static.go @@ -15,9 +15,11 @@ import ( "path/filepath" "strings" texttmpl "text/template" + "time" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" ) @@ -26,6 +28,11 @@ var ( bodyTemplates = template.New("") ) +// GlobalModTime provide a gloabl mod time for embedded asset files +func GlobalModTime(filename string) time.Time { + return timeutil.GetExecutableModTime() +} + // GetAsset get a special asset, only for chi func GetAsset(name string) ([]byte, error) { bs, err := os.ReadFile(filepath.Join(setting.CustomPath, name)) diff --git a/modules/templates/templates_bindata.go b/modules/templates/templates_bindata.go index 887f9eeba2..95f71d0042 100644 --- a/modules/templates/templates_bindata.go +++ b/modules/templates/templates_bindata.go @@ -7,4 +7,4 @@ package templates -//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../templates templates bindata.go +//go:generate go run -mod=vendor ../../build/generate-bindata.go ../../templates templates bindata.go true diff --git a/modules/timeutil/executable.go b/modules/timeutil/executable.go new file mode 100644 index 0000000000..b0a3280753 --- /dev/null +++ b/modules/timeutil/executable.go @@ -0,0 +1,49 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package timeutil + +import ( + "os" + "path/filepath" + "sync" + "time" + + "code.gitea.io/gitea/modules/log" +) + +var executablModTime = time.Now() +var executablModTimeOnce sync.Once + +// GetExecutableModTime get executable file modified time of current process. +func GetExecutableModTime() time.Time { + executablModTimeOnce.Do(func() { + exePath, err := os.Executable() + if err != nil { + log.Error("os.Executable: %v", err) + return + } + + exePath, err = filepath.Abs(exePath) + if err != nil { + log.Error("filepath.Abs: %v", err) + return + } + + exePath, err = filepath.EvalSymlinks(exePath) + if err != nil { + log.Error("filepath.EvalSymlinks: %v", err) + return + } + + st, err := os.Stat(exePath) + if err != nil { + log.Error("os.Stat: %v", err) + return + } + + executablModTime = st.ModTime() + }) + return executablModTime +} |