shithub: hugo

Download patch

ref: aca0f6044878bdcdcfec63497759e3b8fce49512
parent: dec9749bbc836225f6a9341c5653e9f04b2a0e9f
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Jul 21 16:02:42 EDT 2015

source/File: Fix data races

--- a/source/file.go
+++ b/source/file.go
@@ -31,9 +31,6 @@
 }
 
 func (f *File) UniqueID() string {
-	if f.uniqueID == "" {
-		f.uniqueID = helpers.Md5String(f.LogicalName())
-	}
 	return f.uniqueID
 }
 
@@ -51,18 +48,10 @@
 }
 
 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) 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 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) {