mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 21:39:10 +00:00
Use full path for output spec
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
9f5e141437
commit
221781bd0b
@ -167,11 +167,15 @@ func (m command) run(c *cli.Context, cfg *config) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = createParentDirsIfRequired(cfg.output)
|
path := cfg.output
|
||||||
if err != nil {
|
if filepath.Clean(filepath.Dir(path)) == "." {
|
||||||
return fmt.Errorf("failed to create parent folders for output file: %v", err)
|
pwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get current working directory: %v", err)
|
||||||
|
}
|
||||||
|
path = filepath.Join(pwd, path)
|
||||||
}
|
}
|
||||||
return spec.Save(cfg.output)
|
return spec.Save(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatFromFilename(filename string) string {
|
func formatFromFilename(filename string) string {
|
||||||
@ -270,14 +274,3 @@ func MergeDeviceSpecs(deviceSpecs []specs.Device, mergedDeviceName string) (spec
|
|||||||
}
|
}
|
||||||
return merged, nil
|
return merged, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// createParentDirsIfRequired creates the parent folders of the specified path if requried.
|
|
||||||
// Note that MkdirAll does not specifically check whether the specified path is non-empty and raises an error if it is.
|
|
||||||
// The path will be empty if filename in the current folder is specified, for example
|
|
||||||
func createParentDirsIfRequired(filename string) error {
|
|
||||||
dir := filepath.Dir(filename)
|
|
||||||
if dir == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return os.MkdirAll(dir, 0755)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user