File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,8 @@ func (c *Config) File() string {
8585}
8686
8787func (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+ }
You can’t perform that action at this time.
0 commit comments