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

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