From 74ea7f1a2577e03eedf68269f40d03b944eb4f9a Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 4 Jan 2024 21:04:38 -0700 Subject: [PATCH] fix: config overwrite fails with exit code 1 if wrong permissions (#7246) * fix: config overwrite fails with exit code 1 if wrong permissions * changelog * lint --- CHANGELOG.md | 1 + cmd/osmosisd/cmd/root.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bc2e3d89ab..78708f37254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug Fixes * [#7233](https://github.com/osmosis-labs/osmosis/pull/7233) fix: config overwrite ignores app.toml values +* [#7246](https://github.com/osmosis-labs/osmosis/pull/7246) fix: config overwrite fails with exit code 1 if wrong permissions ## v21.1.5 diff --git a/cmd/osmosisd/cmd/root.go b/cmd/osmosisd/cmd/root.go index 35490dbc08d..af7d0ae27fa 100644 --- a/cmd/osmosisd/cmd/root.go +++ b/cmd/osmosisd/cmd/root.go @@ -419,7 +419,7 @@ func overwriteConfigTomlValues(serverCtx *server.Context) error { // Initialize default config tmcConfig := tmcfg.DefaultConfig() - _, err := os.Stat(configFilePath) + fileInfo, err := os.Stat(configFilePath) if err != nil { // something besides a does not exist error if !os.IsNotExist(err) { @@ -465,9 +465,14 @@ func overwriteConfigTomlValues(serverCtx *server.Context) error { fmt.Printf("failed to write to %s: %s\n", configFilePath, err) } }() - // It will be re-read in server.InterceptConfigsPreRunHandler - // this may panic for permissions issues. So we catch the panic. - tmcfg.WriteConfigFile(configFilePath, serverCtx.Config) + + // Check if the file is writable + if fileInfo.Mode()&os.FileMode(0200) != 0 { + // It will be re-read in server.InterceptConfigsPreRunHandler + // this may panic for permissions issues. So we catch the panic. + // Note that this exits with a non-zero exit code if fails to write the file. + tmcfg.WriteConfigFile(configFilePath, serverCtx.Config) + } } return nil }