Ensure that parent directories exist for config files

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-07-03 15:22:30 +02:00
parent baf94181aa
commit 6342dae0e9
2 changed files with 12 additions and 1 deletions

View File

@ -13,10 +13,13 @@
* Fix bug in creation of `/dev/char` symlinks by failing operation if kernel modules are not loaded.
* Add option to load kernel modules when creating device nodes
* Add option to create device nodes when creating `/dev/char` symlinks
* Bump CUDA base image version to 12.1.1.
* Create ouput folders if required when running `nvidia-ctk runtime configure`
* [libnvidia-container] Support OpenSSL 3 with the Encrypt/Decrypt library
* [toolkit-container] Bump CUDA base image version to 12.1.1.
## v1.13.1
* Update `update-ldcache` hook to only update ldcache if it exists.

View File

@ -19,6 +19,7 @@ package engine
import (
"fmt"
"os"
"path/filepath"
)
// Config represents a runtime config
@ -43,6 +44,13 @@ func (c Config) Write(output []byte) (int, error) {
return 0, nil
}
if dir := filepath.Dir(path); dir != "" {
err := os.MkdirAll(dir, 0755)
if err != nil {
return 0, fmt.Errorf("unable to create directory %v: %v", dir, err)
}
}
f, err := os.Create(path)
if err != nil {
return 0, fmt.Errorf("unable to open %v for writing: %v", path, err)