@@ -282,35 +282,31 @@ func (c *Cache) highestPrioritySpecDir() (string, int) {
282282// WriteSpec writes a Spec file with the given content into the highest
283283// priority Spec directory. If name has a "json" or "yaml" extension it
284284// choses the encoding. Otherwise the default YAML encoding is used.
285+ //
286+ // Deprecated: use producer.NewSpecWriter instead.
285287func (c * Cache ) WriteSpec (raw * cdi.Spec , name string ) error {
286288 var (
287289 specDir string
288- prio int
289- spec * Spec
290290 err error
291291 )
292- specDir , prio = c .highestPrioritySpecDir ()
292+ specDir , _ = c .highestPrioritySpecDir ()
293293 if specDir == "" {
294294 return errors .New ("no Spec directories to write to" )
295295 }
296296
297297 path := filepath .Join (specDir , name )
298-
299- // We call newSpec to perform the required validation.
300- // This also sets the extension of the path.
301- spec , err = newSpec (raw , path , prio )
302- if err != nil {
303- return err
298+ if ext := filepath .Ext (path ); ext != ".yaml" && ext != ".json" {
299+ path += defaultSpecExt
304300 }
301+ path = filepath .Clean (path )
305302
306303 p , err := producer .NewSpecWriter (
307- producer .WithSpecFormat (producer .SpecFormatYAML ),
308304 producer .WithOverwrite (true ),
309305 )
310306 if err != nil {
311307 return err
312308 }
313- if _ , err := p .Save (spec . Spec , spec . path ); err != nil {
309+ if _ , err := p .Save (raw , path ); err != nil {
314310 return err
315311 }
316312 return nil
0 commit comments