From 62d9b5f71d251236ae9611ef86e15b1ce4fd2642 Mon Sep 17 00:00:00 2001 From: xu yang Date: Thu, 25 Jul 2024 02:29:29 +0000 Subject: [PATCH] fix the failure when updating overlay files existing on different partitions Signed-off-by: xu yang --- CHANGELOG.md | 1 + internal/app/wwctl/overlay/edit/main.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce4f6da0..9e00980f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Ensure autobuilt overlays include contextual overlay contents. #1296 +- Fix the failure when updating overlay files existing on different partitions. #1312 ## v4.5.5, 2024-07-05 diff --git a/internal/app/wwctl/overlay/edit/main.go b/internal/app/wwctl/overlay/edit/main.go index 07a41ce2..ae5a8cdc 100644 --- a/internal/app/wwctl/overlay/edit/main.go +++ b/internal/app/wwctl/overlay/edit/main.go @@ -115,10 +115,17 @@ func CobraRunE(cmd *cobra.Command, args []string) error { } } + // try renaming the tempfile to overlayfile first err := os.Rename(tempFile.Name(), overlayFile) if err != nil { - wwlog.Error("Unable to update %s: %s", overlayFile, err) - os.Exit(1) + // if it fails, which probably means that they exists on different partitions + // fallback to data copy + wwlog.Debug("Unable to rename temp file: %s to overlay file: %s, try copying the data", tempFile.Name(), overlayFile) + cerr := util.CopyFile(tempFile.Name(), overlayFile) + if cerr != nil { + wwlog.Error("Unable to copy data from temp file: %s to target file: %s, err: %s", tempFile.Name(), overlayFile, err) + os.Exit(1) + } } return nil