Skip to content

Commit

Permalink
Normalize config right before writing it
Browse files Browse the repository at this point in the history
This gets rid of any old legacy files that might be lying around.
We don't do any rewrites of custom config files.
  • Loading branch information
kytrinyx committed Aug 26, 2014
1 parent a9c78f9 commit 6ec5876
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (c *Config) File() string {
}

func (c *Config) Write() error {
renameLegacy()

// truncates existing file if it exists
f, err := os.Create(c.file)
if err != nil {
Expand Down Expand Up @@ -231,3 +233,21 @@ func (c *Config) sanitize() {
c.Dir = strings.TrimSpace(c.Dir)
c.Hostname = strings.TrimSpace(c.Hostname)
}

// renameLegacy normalizes the default config file name.
// This function will bail silently if any error occurs.
func renameLegacy() {
dir, err := Home()
if err != nil {
return
}

legacyPath := filepath.Join(dir, LegacyFile)
if _, err = os.Stat(legacyPath); err != nil {
return
}

correctPath := filepath.Join(dir, File)
os.Rename(legacyPath, correctPath)
return
}

0 comments on commit 6ec5876

Please sign in to comment.