Don't store assets modified time into generated files (#18193)
This commit is contained in:
+26
-12
@@ -30,7 +30,9 @@ func Generate(input http.FileSystem, opt Options) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var toc toc
|
||||
var toc = toc{
|
||||
UseGlobalModTime: opt.UseGlobalModTime,
|
||||
}
|
||||
err = findAndWriteFiles(buf, input, &toc)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -56,6 +58,8 @@ type toc struct {
|
||||
|
||||
HasCompressedFile bool // There's at least one compressedFile.
|
||||
HasFile bool // There's at least one uncompressed file.
|
||||
UseGlobalModTime bool // copy from opt
|
||||
|
||||
}
|
||||
|
||||
// fileInfo is a definition of a file.
|
||||
@@ -64,14 +68,16 @@ type fileInfo struct {
|
||||
Name string
|
||||
ModTime time.Time
|
||||
UncompressedSize int64
|
||||
UseGlobalModTime bool
|
||||
}
|
||||
|
||||
// dirInfo is a definition of a directory.
|
||||
type dirInfo struct {
|
||||
Path string
|
||||
Name string
|
||||
ModTime time.Time
|
||||
Entries []string
|
||||
Path string
|
||||
Name string
|
||||
ModTime time.Time
|
||||
Entries []string
|
||||
UseGlobalModTime bool
|
||||
}
|
||||
|
||||
// findAndWriteFiles recursively finds all the file paths in the given directory tree.
|
||||
@@ -91,6 +97,7 @@ func findAndWriteFiles(buf *bytes.Buffer, fs http.FileSystem, toc *toc) error {
|
||||
Name: pathpkg.Base(path),
|
||||
ModTime: fi.ModTime().UTC(),
|
||||
UncompressedSize: fi.Size(),
|
||||
UseGlobalModTime: toc.UseGlobalModTime,
|
||||
}
|
||||
|
||||
marker := buf.Len()
|
||||
@@ -125,10 +132,11 @@ func findAndWriteFiles(buf *bytes.Buffer, fs http.FileSystem, toc *toc) error {
|
||||
}
|
||||
|
||||
dir := &dirInfo{
|
||||
Path: path,
|
||||
Name: pathpkg.Base(path),
|
||||
ModTime: fi.ModTime().UTC(),
|
||||
Entries: entries,
|
||||
Path: path,
|
||||
Name: pathpkg.Base(path),
|
||||
ModTime: fi.ModTime().UTC(),
|
||||
Entries: entries,
|
||||
UseGlobalModTime: toc.UseGlobalModTime,
|
||||
}
|
||||
|
||||
toc.dirs = append(toc.dirs, dir)
|
||||
@@ -242,7 +250,9 @@ var {{.VariableName}} = func() http.FileSystem {
|
||||
|
||||
{{define "CompressedFileInfo-Before"}} {{quote .Path}}: &vfsgen۰CompressedFileInfo{
|
||||
name: {{quote .Name}},
|
||||
{{if not .UseGlobalModTime}}
|
||||
modTime: {{template "Time" .ModTime}},
|
||||
{{end}}
|
||||
uncompressedSize: {{.UncompressedSize}},
|
||||
{{/* This blank line separating compressedContent is neccessary to prevent potential gofmt issues. See issue #19. */}}
|
||||
compressedContent: []byte("{{end}}{{define "CompressedFileInfo-After"}}"),
|
||||
@@ -253,7 +263,9 @@ var {{.VariableName}} = func() http.FileSystem {
|
||||
|
||||
{{define "FileInfo-Before"}} {{quote .Path}}: &vfsgen۰FileInfo{
|
||||
name: {{quote .Name}},
|
||||
{{if not .UseGlobalModTime}}
|
||||
modTime: {{template "Time" .ModTime}},
|
||||
{{end}}
|
||||
content: []byte("{{end}}{{define "FileInfo-After"}}"),
|
||||
},
|
||||
{{end}}
|
||||
@@ -262,7 +274,9 @@ var {{.VariableName}} = func() http.FileSystem {
|
||||
|
||||
{{define "DirInfo"}} {{quote .Path}}: &vfsgen۰DirInfo{
|
||||
name: {{quote .Name}},
|
||||
{{if not .UseGlobalModTime}}
|
||||
modTime: {{template "Time" .ModTime}},
|
||||
{{end}}
|
||||
},
|
||||
{{end}}
|
||||
|
||||
@@ -335,7 +349,7 @@ func (f *vfsgen۰CompressedFileInfo) GzipBytes() []byte {
|
||||
func (f *vfsgen۰CompressedFileInfo) Name() string { return f.name }
|
||||
func (f *vfsgen۰CompressedFileInfo) Size() int64 { return f.uncompressedSize }
|
||||
func (f *vfsgen۰CompressedFileInfo) Mode() os.FileMode { return 0444 }
|
||||
func (f *vfsgen۰CompressedFileInfo) ModTime() time.Time { return f.modTime }
|
||||
func (f *vfsgen۰CompressedFileInfo) ModTime() time.Time { return {{if .UseGlobalModTime}}GlobalModTime(f.name){{else}}f.modTime{{end}} }
|
||||
func (f *vfsgen۰CompressedFileInfo) IsDir() bool { return false }
|
||||
func (f *vfsgen۰CompressedFileInfo) Sys() interface{} { return nil }
|
||||
|
||||
@@ -407,7 +421,7 @@ func (f *vfsgen۰FileInfo) NotWorthGzipCompressing() {}
|
||||
func (f *vfsgen۰FileInfo) Name() string { return f.name }
|
||||
func (f *vfsgen۰FileInfo) Size() int64 { return int64(len(f.content)) }
|
||||
func (f *vfsgen۰FileInfo) Mode() os.FileMode { return 0444 }
|
||||
func (f *vfsgen۰FileInfo) ModTime() time.Time { return f.modTime }
|
||||
func (f *vfsgen۰FileInfo) ModTime() time.Time { return {{if .UseGlobalModTime}}GlobalModTime(f.name){{else}}f.modTime{{end}} }
|
||||
func (f *vfsgen۰FileInfo) IsDir() bool { return false }
|
||||
func (f *vfsgen۰FileInfo) Sys() interface{} { return nil }
|
||||
|
||||
@@ -440,7 +454,7 @@ func (d *vfsgen۰DirInfo) Stat() (os.FileInfo, error) { return d, nil }
|
||||
func (d *vfsgen۰DirInfo) Name() string { return d.name }
|
||||
func (d *vfsgen۰DirInfo) Size() int64 { return 0 }
|
||||
func (d *vfsgen۰DirInfo) Mode() os.FileMode { return 0755 | os.ModeDir }
|
||||
func (d *vfsgen۰DirInfo) ModTime() time.Time { return d.modTime }
|
||||
func (d *vfsgen۰DirInfo) ModTime() time.Time { return {{if .UseGlobalModTime}}GlobalModTime(d.name){{else}}d.modTime{{end}} }
|
||||
func (d *vfsgen۰DirInfo) IsDir() bool { return true }
|
||||
func (d *vfsgen۰DirInfo) Sys() interface{} { return nil }
|
||||
|
||||
|
||||
+4
@@ -26,6 +26,10 @@ type Options struct {
|
||||
// VariableComment is the comment of the http.FileSystem variable in the generated code.
|
||||
// If left empty, it defaults to "{{.VariableName}} statically implements the virtual filesystem provided to vfsgen.".
|
||||
VariableComment string
|
||||
|
||||
// UseGlobalModTime indicates that not retrieve files' modified time if it's true. Once this
|
||||
// is true, you have to define a function GlobalModTime(filename string) time.Time in the same package of generated files
|
||||
UseGlobalModTime bool
|
||||
}
|
||||
|
||||
// fillMissing sets default values for mandatory options that are left empty.
|
||||
|
||||
Vendored
+2
-1
@@ -727,7 +727,7 @@ github.com/sergi/go-diff/diffmatchpatch
|
||||
# github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
|
||||
## explicit
|
||||
github.com/shurcooL/httpfs/vfsutil
|
||||
# github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
|
||||
# github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
|
||||
## explicit
|
||||
github.com/shurcooL/vfsgen
|
||||
# github.com/sirupsen/logrus v1.8.1
|
||||
@@ -1061,3 +1061,4 @@ xorm.io/xorm/schemas
|
||||
xorm.io/xorm/tags
|
||||
# github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
|
||||
# github.com/golang-jwt/jwt v3.2.1+incompatible => github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
# github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
|
||||
|
||||
Reference in New Issue
Block a user