github.com/opentofu/opentofu@v1.7.1/internal/command/cliconfig/util.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package cliconfig 7 8 import "os" 9 10 func getNewOrLegacyPath(newPath string, legacyPath string) (string, error) { 11 // If the legacy directory exists, but the new directory does not, then use the legacy directory, for backwards compatibility reasons. 12 // Otherwise, use the new directory. 13 if _, err := os.Stat(legacyPath); err == nil { 14 if _, err := os.Stat(newPath); os.IsNotExist(err) { 15 return legacyPath, nil 16 } 17 } 18 19 return newPath, nil 20 }