Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep config file permissions #1

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions configupgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ func Do(configPath string, save bool, upgrader BaseUpgrader, additional ...Upgra
if err != nil {
return output, true, fmt.Errorf("failed to create temp file for writing config: %w", err)
}
var fi, err = os.Stat(configPath)
if err != nil {
_ = os.Remove(tempFile.Name())
return output, true, fmt.Errorf("failed to get config permissions: %w", err)
}
err = tempFile.Chmod(fi.Mode())
if err != nil {
_ = os.Remove(tempFile.Name())
return output, true, fmt.Errorf("failed to set permissions to temp file: %w", err)
}
_, err = tempFile.Write(output)
if err != nil {
_ = os.Remove(tempFile.Name())
Expand Down