@@ -168,7 +168,7 @@ func remarshalJSON(data []byte) ([]byte, error) {
168168 return buf .Bytes (), nil
169169}
170170
171- func (d * dashboard ) saveSerializedDashboard (ctx context.Context , b * bundle. Bundle , dashboard * dashboards.Dashboard , filename string ) error {
171+ func (d * dashboard ) saveSerializedDashboard (ctx context.Context , dashboard * dashboards.Dashboard , filename string ) error {
172172 // Unmarshal and remarshal the serialized dashboard to ensure it is formatted correctly.
173173 // The result will have alphabetically sorted keys and be indented.
174174 data , err := remarshalJSON ([]byte (dashboard .SerializedDashboard ))
@@ -179,24 +179,18 @@ func (d *dashboard) saveSerializedDashboard(ctx context.Context, b *bundle.Bundl
179179 // Clean the filename to ensure it is a valid path (and can be used on this OS).
180180 filename = filepath .Clean (filename )
181181
182- // Attempt to make the path relative to the bundle root.
183- rel , err := filepath .Rel (b .BundleRootPath , filename )
184- if err != nil {
185- rel = filename
186- }
187-
188182 // Verify that the file does not already exist.
189183 info , err := d .outputFiler .Stat (ctx , filename )
190184 if err == nil {
191185 if info .IsDir () {
192- return fmt .Errorf ("%s is a directory" , rel )
186+ return fmt .Errorf ("%s is a directory" , filename )
193187 }
194188 if ! d .force {
195- return fmt .Errorf ("%s already exists. Use --force to overwrite" , rel )
189+ return fmt .Errorf ("%s already exists. Use --force to overwrite" , filename )
196190 }
197191 }
198192
199- fmt .Fprintf (d .out , "Writing dashboard to %q\n " , rel )
193+ fmt .Fprintf (d .out , "Writing dashboard to %q\n " , filename )
200194
201195 mode := []filer.WriteMode {filer .CreateParentDirectories }
202196 if d .force {
@@ -205,11 +199,11 @@ func (d *dashboard) saveSerializedDashboard(ctx context.Context, b *bundle.Bundl
205199 return d .outputFiler .Write (ctx , filename , bytes .NewReader (data ), mode ... )
206200}
207201
208- func (d * dashboard ) saveConfiguration (ctx context.Context , b * bundle. Bundle , dashboard * dashboards.Dashboard , key string ) error {
202+ func (d * dashboard ) saveConfiguration (ctx context.Context , dashboard * dashboards.Dashboard , key string ) error {
209203 // Save serialized dashboard definition to the dashboard directory.
210204 dashboardBasename := key + ".lvdash.json"
211205 dashboardPath := filepath .Join (d .dashboardDir , dashboardBasename )
212- err := d .saveSerializedDashboard (ctx , b , dashboard , dashboardPath )
206+ err := d .saveSerializedDashboard (ctx , dashboard , dashboardPath )
213207 if err != nil {
214208 return err
215209 }
@@ -234,13 +228,7 @@ func (d *dashboard) saveConfiguration(ctx context.Context, b *bundle.Bundle, das
234228 "display_name" : yaml .DoubleQuotedStyle ,
235229 })
236230
237- // Attempt to make the path relative to the bundle root.
238- rel , err := filepath .Rel (b .BundleRootPath , resourcePath )
239- if err != nil {
240- rel = resourcePath
241- }
242-
243- fmt .Fprintf (d .out , "Writing configuration to %q\n " , rel )
231+ fmt .Fprintf (d .out , "Writing configuration to %q\n " , resourcePath )
244232 err = saver .SaveAsYAMLToFiler (ctx , d .outputFiler , result , resourcePath , d .force )
245233 if err != nil {
246234 return err
@@ -304,7 +292,7 @@ func (d *dashboard) updateDashboardForResource(ctx context.Context, b *bundle.Bu
304292 }
305293
306294 if etag != dashboard .Etag {
307- err = d .saveSerializedDashboard (ctx , b , dashboard , dashboardPath )
295+ err = d .saveSerializedDashboard (ctx , dashboard , dashboardPath )
308296 if err != nil {
309297 logdiag .LogError (ctx , err )
310298 return
@@ -336,7 +324,7 @@ func (d *dashboard) generateForExisting(ctx context.Context, b *bundle.Bundle, d
336324 }
337325
338326 key := textutil .NormalizeString (dashboard .DisplayName )
339- err = d .saveConfiguration (ctx , b , dashboard , key )
327+ err = d .saveConfiguration (ctx , dashboard , key )
340328 if err != nil {
341329 logdiag .LogError (ctx , err )
342330 }
@@ -352,12 +340,18 @@ func (d *dashboard) generateForExisting(ctx context.Context, b *bundle.Bundle, d
352340}
353341
354342func (d * dashboard ) initialize (ctx context.Context , b * bundle.Bundle ) {
355- // Make the paths absolute if they aren't already.
356- if ! filepath .IsAbs (d .resourceDir ) {
357- d .resourceDir = filepath .Join (b .BundleRootPath , d .resourceDir )
343+ var err error
344+
345+ // Make paths relative to the bundle root (required for the filer which is rooted there).
346+ d .resourceDir , err = makeRelativeToRoot (b .BundleRootPath , d .resourceDir )
347+ if err != nil {
348+ logdiag .LogError (ctx , err )
349+ return
358350 }
359- if ! filepath .IsAbs (d .dashboardDir ) {
360- d .dashboardDir = filepath .Join (b .BundleRootPath , d .dashboardDir )
351+ d .dashboardDir , err = makeRelativeToRoot (b .BundleRootPath , d .dashboardDir )
352+ if err != nil {
353+ logdiag .LogError (ctx , err )
354+ return
361355 }
362356
363357 // Make sure we know how the dashboard path is relative to the resource path.
0 commit comments