From aca0f6044878bdcdcfec63497759e3b8fce49512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 21 Jul 2015 20:02:42 +0200 Subject: [PATCH] source/File: Fix data races --- source/file.go | 29 +++++++++-------------------- 1 file 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) {