resources: file: Don't modify resource in Init

This didn't break anything previously, but technically wasn't correct.
Pure functions are superior in this case!
This commit is contained in:
James Shubin
2017-02-16 00:24:04 -05:00
parent 57e919d7e5
commit 2647d09b8f

View File

@@ -142,9 +142,6 @@ func (obj *FileRes) uid() (int, error) {
// Init runs some startup code for this resource. // Init runs some startup code for this resource.
func (obj *FileRes) Init() error { func (obj *FileRes) Init() error {
obj.sha256sum = "" obj.sha256sum = ""
if obj.Path == "" { // use the name as the path default if missing
obj.Path = obj.BaseRes.Name
}
obj.path = obj.GetPath() // compute once obj.path = obj.GetPath() // compute once
obj.isDir = strings.HasSuffix(obj.path, "/") // dirs have trailing slashes obj.isDir = strings.HasSuffix(obj.path, "/") // dirs have trailing slashes
@@ -155,10 +152,15 @@ func (obj *FileRes) Init() error {
// GetPath returns the actual path to use for this resource. It computes this // GetPath returns the actual path to use for this resource. It computes this
// after analysis of the Path, Dirname and Basename values. Dirs end with slash. // after analysis of the Path, Dirname and Basename values. Dirs end with slash.
func (obj *FileRes) GetPath() string { func (obj *FileRes) GetPath() string {
d := util.Dirname(obj.Path) p := obj.Path
b := util.Basename(obj.Path) if obj.Path == "" { // use the name as the path default if missing
p = obj.BaseRes.Name
}
d := util.Dirname(p)
b := util.Basename(p)
if obj.Dirname == "" && obj.Basename == "" { if obj.Dirname == "" && obj.Basename == "" {
return obj.Path return p
} }
if obj.Dirname == "" { if obj.Dirname == "" {
return d + obj.Basename return d + obj.Basename