nuageinit: Create parent directories in write_files

Currently, 'write_files' does not create parent directories, and
'runcmd' cannot be used here, since those scripts run after the files
have been written. The only workaround is to create the files in an
existing directory, such as '/root' or '/tmp', and then move those
files using 'runcmd', but this is cumbersome when there are many files,
even if they are small.

With this change, nuageinit now creates the parent directories for each
file using the path field, which mimics the same behavior as in
cloud-init.

Permissions and ownership can also be configured using 'runcmd'.

Reviewed by:            bapt@
Approved by:            bapt@
Differential Revision:  https://reviews.freebsd.org/D57395
This commit is contained in:
Jesús Daniel Colmenares Oviedo
2026-06-08 17:05:09 -04:00
parent b16c731b01
commit ea3426bc80
2 changed files with 3 additions and 2 deletions
+1
View File
@@ -832,6 +832,7 @@ local function addfile(file, defer)
root = "" root = ""
end end
local filepath = root .. file.path local filepath = root .. file.path
mkdir_p(dirname(filepath))
local f = assert(io.open(filepath, mode)) local f = assert(io.open(filepath, mode))
if content then if content then
f:write(content) f:write(content)
+2 -2
View File
@@ -3,7 +3,7 @@
.\" Copyright (c) 2025 Baptiste Daroussin <bapt@FreeBSD.org> .\" Copyright (c) 2025 Baptiste Daroussin <bapt@FreeBSD.org>
.\" Copyright (c) 2025 Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org> .\" Copyright (c) 2025 Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org>
.\" .\"
.Dd June 6, 2026 .Dd June 8, 2026
.Dt NUAGEINIT 7 .Dt NUAGEINIT 7
.Os .Os
.Sh NAME .Sh NAME
@@ -615,7 +615,7 @@ and
are supported for now. are supported for now.
.It Ic path .It Ic path
The path of the file to be created. The path of the file to be created.
.Pq Note intermerdiary directories will not be created . .Pq Note intermerdiary directories will be created .
.It Ic permissions .It Ic permissions
A string representing the permission of the file in octal. A string representing the permission of the file in octal.
.It Ic owner .It Ic owner