mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Properly create output for config file
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
@@ -39,13 +39,23 @@ func (o Options) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOutput returns the effective output
|
||||
func (o Options) GetOutput() string {
|
||||
if o.InPlace {
|
||||
return o.Config
|
||||
}
|
||||
|
||||
return o.Output
|
||||
}
|
||||
|
||||
// EnsureOutputFolder creates the output folder if it does not exist.
|
||||
// If the output folder is not specified (i.e. output to STDOUT), it is ignored.
|
||||
func (o Options) EnsureOutputFolder() error {
|
||||
if o.Output == "" {
|
||||
output := o.GetOutput()
|
||||
if output == "" {
|
||||
return nil
|
||||
}
|
||||
if dir := filepath.Dir(o.Output); dir != "" {
|
||||
if dir := filepath.Dir(output); dir != "" {
|
||||
return os.MkdirAll(dir, 0755)
|
||||
}
|
||||
return nil
|
||||
@@ -53,11 +63,12 @@ func (o Options) EnsureOutputFolder() error {
|
||||
|
||||
// CreateOutput creates the writer for the output.
|
||||
func (o Options) CreateOutput() (io.WriteCloser, error) {
|
||||
if o.Output != "" {
|
||||
return os.Create(o.Output)
|
||||
output := o.GetOutput()
|
||||
if output == "" {
|
||||
return nullCloser{os.Stdout}, nil
|
||||
}
|
||||
|
||||
return nullCloser{os.Stdout}, nil
|
||||
return os.Create(output)
|
||||
}
|
||||
|
||||
// nullCloser is a writer that does nothing on Close.
|
||||
|
||||
Reference in New Issue
Block a user