From 2647d09b8f0148690f7d35683e2cc6ef568179c9 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 16 Feb 2017 00:24:04 -0500 Subject: [PATCH] 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! --- resources/file.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/resources/file.go b/resources/file.go index 539dde9c..cd375c51 100644 --- a/resources/file.go +++ b/resources/file.go @@ -142,9 +142,6 @@ func (obj *FileRes) uid() (int, error) { // Init runs some startup code for this resource. func (obj *FileRes) Init() error { 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.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 // after analysis of the Path, Dirname and Basename values. Dirs end with slash. func (obj *FileRes) GetPath() string { - d := util.Dirname(obj.Path) - b := util.Basename(obj.Path) + p := 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 == "" { - return obj.Path + return p } if obj.Dirname == "" { return d + obj.Basename