Preserve file permissions during wwctl overlay edit
- Fixes: #1886 Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user