Skip to content

Commit

Permalink
fix: config overwrite fails with exit code 1 if wrong permissions (#7246
Browse files Browse the repository at this point in the history
)

* fix: config overwrite fails with exit code 1 if wrong permissions

* changelog

* lint
  • Loading branch information
p0mvn authored Jan 5, 2024
1 parent e79f7b6 commit 74ea7f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 74ea7f1

Please sign in to comment.