-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use an atomic config write strategy on Windows
- Introduce a util.WriteFilePseudoAtomic() func for consuming projects - While the above func is multi-platform, limit to Windows usage for now [NO NEW TESTS NEEDED] Signed-off-by: Jason T. Greene <[email protected]>
- Loading branch information
Showing
4 changed files
with
120 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/BurntSushi/toml" | ||
) | ||
|
||
// Write writes the configuration to the default file | ||
func (c *Config) Write() error { | ||
var err error | ||
path, err := customConfigFile() | ||
if err != nil { | ||
return err | ||
} | ||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { | ||
return err | ||
} | ||
configFile, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0o644) | ||
if err != nil { | ||
return err | ||
} | ||
defer configFile.Close() | ||
enc := toml.NewEncoder(configFile) | ||
if err := enc.Encode(c); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters