Preserve file permissions during wwctl overlay edit

- Fixes: #1886

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-07-02 08:06:13 -06:00
parent eaad409bf0
commit 48bace55f6
2 changed files with 5 additions and 10 deletions

View File

@@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fixed sleep/rebooting on error during GRUB boot. #1894
- Fixed IPMI VLAN configuration. #1892
- Fixed `wwctl image shell --help` to fit properly within 80 columns.
- Preserve existing permissions during `wwctl overlay edit`. #1886
### Changed

View File

@@ -111,16 +111,10 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
}
}
// try renaming the tempfile to overlayfile first
err = os.Rename(tempFile.Name(), overlayFile)
if err != nil {
// 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 {
return fmt.Errorf("unable to copy data from temp file: %s to target file: %s, err: %s", tempFile.Name(), overlayFile, err)
}
// using CopyFile preserves target file permissions
cerr := util.CopyFile(tempFile.Name(), overlayFile)
if cerr != nil {
return fmt.Errorf("unable to copy data from temp file: %s to target file: %s, err: %s", tempFile.Name(), overlayFile, err)
}
return nil