fix the failure when updating overlay files existing on different partitions

Signed-off-by: xu yang <xyang@ciq.com>
This commit is contained in:
xu yang
2024-07-25 02:29:29 +00:00
parent b61e391890
commit 62d9b5f71d
2 changed files with 10 additions and 2 deletions

View File

@@ -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

View File

@@ -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