Skip to content

Commit aca0f60

Browse files
committed
source/File: Fix data races
1 parent dec9749 commit aca0f60

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

source/file.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ type File struct {
3131
}
3232

3333
func (f *File) UniqueID() string {
34-
if f.uniqueID == "" {
35-
f.uniqueID = helpers.Md5String(f.LogicalName())
36-
}
3734
return f.uniqueID
3835
}
3936

@@ -51,18 +48,10 @@ func (f *File) BaseFileName() string {
5148
}
5249

5350
func (f *File) Section() string {
54-
if f.section != "" {
55-
return f.section
56-
}
57-
f.section = helpers.GuessSection(f.Dir())
5851
return f.section
5952
}
6053

6154
func (f *File) LogicalName() string {
62-
if f.logicalName != "" {
63-
return f.logicalName
64-
}
65-
_, f.logicalName = filepath.Split(f.relpath)
6655
return f.logicalName
6756
}
6857

@@ -71,18 +60,10 @@ func (f *File) SetDir(dir string) {
7160
}
7261

7362
func (f *File) Dir() string {
74-
if f.dir != "" {
75-
return f.dir
76-
}
77-
f.dir, _ = filepath.Split(f.relpath)
7863
return f.dir
7964
}
8065

8166
func (f *File) Extension() string {
82-
if f.ext != "" {
83-
return f.ext
84-
}
85-
f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
8667
return f.ext
8768
}
8869

@@ -101,9 +82,17 @@ func NewFileWithContents(relpath string, content io.Reader) *File {
10182
}
10283

10384
func NewFile(relpath string) *File {
104-
return &File{
85+
f := &File{
10586
relpath: relpath,
10687
}
88+
89+
f.dir, _ = filepath.Split(f.relpath)
90+
_, f.logicalName = filepath.Split(f.relpath)
91+
f.ext = strings.TrimPrefix(filepath.Ext(f.LogicalName()), ".")
92+
f.section = helpers.GuessSection(f.Dir())
93+
f.uniqueID = helpers.Md5String(f.LogicalName())
94+
95+
return f
10796
}
10897

10998
func NewFileFromAbs(base, fullpath string, content io.Reader) (f *File, err error) {

0 commit comments

Comments
 (0)