mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
source/File: Fix data races
This commit is contained in:
parent
dec9749bbc
commit
aca0f60448
1 changed files with 9 additions and 20 deletions
|
@ -31,9 +31,6 @@ type File struct {
|
|||
}
|
||||
|
||||
func (f *File) UniqueID() string {
|
||||
if f.uniqueID == "" {
|
||||
f.uniqueID = helpers.Md5String(f.LogicalName())
|
||||
}
|
||||
return f.uniqueID
|
||||
}
|
||||
|
||||
|
@ -51,18 +48,10 @@ func (f *File) BaseFileName() string {
|
|||
}
|
||||
|
||||
func (f *File) Section() string {
|
||||
if f.section != "" {
|
||||
return f.section
|
||||
}
|
||||
f.section = helpers.GuessSection(f.Dir())
|
||||
return f.section
|
||||
}
|
||||
|
||||
func (f *File) LogicalName() string {
|
||||
if f.logicalName != "" {
|
||||
return f.logicalName
|
||||
}
|
||||
_, f.logicalName = filepath.Split(f.relpath)
|
||||
return f.logicalName
|
||||
}
|
||||
|
||||
|
@ -71,18 +60,10 @@ func (f *File) SetDir(dir string) {
|
|||
}
|
||||
|
||||
func (f *File) Dir() string {
|
||||
if f.dir != "" {
|
||||
return f.dir
|
||||
}
|
||||
f.dir, _ = filepath.Split(f.relpath)
|
||||
return f.dir
|
||||
}
|
||||
|
||||
func (f *File) Extension() string {
|
||||
if f.ext != "" {
|
||||
return f.ext
|
||||
}
|
||||
f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
|
||||
return f.ext
|
||||
}
|
||||
|
||||
|
@ -101,9 +82,17 @@ func NewFileWithContents(relpath string, content io.Reader) *File {
|
|||
}
|
||||
|
||||
func NewFile(relpath string) *File {
|
||||
return &File{
|
||||
f := &File{
|
||||
relpath: relpath,
|
||||
}
|
||||
|
||||
f.dir, _ = filepath.Split(f.relpath)
|
||||
_, f.logicalName = filepath.Split(f.relpath)
|
||||
f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
|
||||
f.section = helpers.GuessSection(f.Dir())
|
||||
f.uniqueID = helpers.Md5String(f.LogicalName())
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func NewFileFromAbs(base, fullpath string, content io.Reader) (f *File, err error) {
|
||||
|
|
Loading…
Reference in a new issue