From 5b9d088a57403d6169a11945a37061870e6c9115 Mon Sep 17 00:00:00 2001 From: Bludator Date: Tue, 26 Sep 2023 15:17:07 +0200 Subject: [PATCH] Keep config file permissions --- configupgrade/upgrade.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configupgrade/upgrade.go b/configupgrade/upgrade.go index 1dd647c..fb5d92d 100644 --- a/configupgrade/upgrade.go +++ b/configupgrade/upgrade.go @@ -93,6 +93,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())