From e86981fd59ed8bb3b729343cbde6571fcd692128 Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Mon, 14 Jul 2025 08:08:57 +0000 Subject: [PATCH] fix(wwctl): Create overlay edit tempfile in tmpdir When editing an overlay, the temporary file was created within the overlay directory structure. This could lead to the temporary file being included in the overlay if not cleaned up properly. This change modifies the behavior to create the temporary file in the system's default temporary directory, avoiding any potential issues with the overlay itself. Not using this change the temporary file can be seen in the overlay: DEBUG : Using temporary file /usr/share/warewulf/overlays/host/ww-overlay-edit-2879742493 DEBUG : Checking if path exists as a file: /usr/share/warewulf/overlays/host/rootfs/etc/hosts.ww DEBUG : ExecInteractive(tee, [/usr/share/warewulf/overlays/host/ww-overlay-edit-2879742493]) # find /srv | grep ww-overlay /srv/warewulf/overlays/host/ww-overlay-edit-2879742493 With this patch applied: DEBUG : Using temporary file /tmp/ww-overlay-edit-266752840 DEBUG : Checking if path exists as a file: /usr/share/warewulf/overlays/host/rootfs/etc/hosts.ww DEBUG : ExecInteractive(tee, [/tmp/ww-overlay-edit-266752840]) # find /srv | grep ww-overlay Assisted-by: Gemini 2.5 Pro Signed-off-by: Adrian Reber --- CHANGELOG.md | 2 ++ CONTRIBUTORS.md | 1 + internal/app/wwctl/overlay/edit/main.go | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd532bb4..a78a8416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Refactored overlay class. #1968 - `wwclient` places files from the runtime overlay atomically. #1307, #1975 - `wwclient` skips files that do not appear to have been modified. #1984 +- `wwctl overlay edit` again writes temporary files to the default location. + (After #1886 better resolves the underlying issue from #1473.) #1946 ### Fixed diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7d75a19e..657d378a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -48,3 +48,4 @@ * Rafael Lopez @rafalop * Arian Cabrera [@acabrera86](https://github.com/acabrera86) * Dacian Reece-Stremtan [@dacianstremtan](https://github.com/dacianstremtan) +* Adrian Reber diff --git a/internal/app/wwctl/overlay/edit/main.go b/internal/app/wwctl/overlay/edit/main.go index 608d7ed4..3bcf3b32 100644 --- a/internal/app/wwctl/overlay/edit/main.go +++ b/internal/app/wwctl/overlay/edit/main.go @@ -47,7 +47,7 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) { return fmt.Errorf("%s does not exist. Use '--parents' option to create automatically", overlayFileDir) } - tempFile, tempFileErr := os.CreateTemp(myOverlay.Path(), "ww-overlay-edit-") + tempFile, tempFileErr := os.CreateTemp("", "ww-overlay-edit-") if tempFileErr != nil { return fmt.Errorf("unable to create temporary file for editing: %s", tempFileErr) }