Skip to content

Commit 6ec5876

Browse files
committed
Normalize config right before writing it
This gets rid of any old legacy files that might be lying around. We don't do any rewrites of custom config files.
1 parent a9c78f9 commit 6ec5876

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

config/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func (c *Config) File() string {
8585
}
8686

8787
func (c *Config) Write() error {
88+
renameLegacy()
89+
8890
// truncates existing file if it exists
8991
f, err := os.Create(c.file)
9092
if err != nil {
@@ -231,3 +233,21 @@ func (c *Config) sanitize() {
231233
c.Dir = strings.TrimSpace(c.Dir)
232234
c.Hostname = strings.TrimSpace(c.Hostname)
233235
}
236+
237+
// renameLegacy normalizes the default config file name.
238+
// This function will bail silently if any error occurs.
239+
func renameLegacy() {
240+
dir, err := Home()
241+
if err != nil {
242+
return
243+
}
244+
245+
legacyPath := filepath.Join(dir, LegacyFile)
246+
if _, err = os.Stat(legacyPath); err != nil {
247+
return
248+
}
249+
250+
correctPath := filepath.Join(dir, File)
251+
os.Rename(legacyPath, correctPath)
252+
return
253+
}

0 commit comments

Comments
 (0)