Add new or legacy path util

This commit is contained in:
Yaron Yarimi
2023-08-20 18:41:15 +03:00
parent 01421147b2
commit a0c351fc35

View File

@@ -0,0 +1,15 @@
package cliconfig
import "os"
func getNewOrLegacyPath(newPath string, legacyPath string) (string, error) {
// If the legacy directory exists, but the new directory does not, then use the legacy directory, for backwards compatibility reasons.
// Otherwise, use the new directory.
if _, err := os.Stat(legacyPath); err == nil {
if _, err := os.Stat(newPath); os.IsNotExist(err) {
return legacyPath, nil
}
}
return newPath, nil
}