diff options
author | Bjørn Erik Pedersen <[email protected]> | 2015-07-21 20:02:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2015-07-21 20:02:42 +0200 |
commit | aca0f6044878bdcdcfec63497759e3b8fce49512 (patch) | |
tree | 57818f29c522e1b8d89bc34c99811f8e0ea45dc2 /source | |
parent | dec9749bbc836225f6a9341c5653e9f04b2a0e9f (diff) | |
download | hugo-aca0f6044878bdcdcfec63497759e3b8fce49512.tar.gz hugo-aca0f6044878bdcdcfec63497759e3b8fce49512.zip |
source/File: Fix data races
Diffstat (limited to 'source')
-rw-r--r-- | source/file.go | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/source/file.go b/source/file.go index 982a73312..53524ced4 100644 --- a/source/file.go +++ b/source/file.go @@ -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) { |