From 6342dae0e9bae536285862d6d3ab50afa92336bd Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 3 Jul 2023 15:22:30 +0200 Subject: [PATCH] Ensure that parent directories exist for config files Signed-off-by: Evan Lezar --- CHANGELOG.md | 5 ++++- pkg/config/engine/config.go | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2425317f..bd998fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/pkg/config/engine/config.go b/pkg/config/engine/config.go index b9417526..f82a59f2 100644 --- a/pkg/config/engine/config.go +++ b/pkg/config/engine/config.go @@ -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)