From 267090ebcfaa2795f05f2dd966696d571186599b Mon Sep 17 00:00:00 2001 From: srstack Date: Mon, 16 May 2022 12:09:00 +0800 Subject: [PATCH 1/2] fix --- pkg/cluster/spec/profile.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/spec/profile.go b/pkg/cluster/spec/profile.go index cf852cb2e7..2b59532e28 100644 --- a/pkg/cluster/spec/profile.go +++ b/pkg/cluster/spec/profile.go @@ -59,14 +59,18 @@ var initialized = false // The directory will be created before return if it does not already exist. func Initialize(base string) error { tiupData := os.Getenv(tiuplocaldata.EnvNameComponentDataDir) - if tiupData == "" { + tiupHome := os.Getenv(tiuplocaldata.EnvNameHome) + + if tiupData != "" { + profileDir = tiupData + } else if tiupHome != "" { + profileDir = path.Join(tiupHome, tiuplocaldata.StorageParentDir, base) + } else { homeDir, err := getHomeDir() if err != nil { return errors.Trace(err) } profileDir = path.Join(homeDir, ".tiup", tiuplocaldata.StorageParentDir, base) - } else { - profileDir = tiupData } clusterBaseDir := filepath.Join(profileDir, TiUPClusterDir) From 5173c55223a76ef53f13db5c4c7ded36330aea72 Mon Sep 17 00:00:00 2001 From: srstack Date: Mon, 16 May 2022 14:41:58 +0800 Subject: [PATCH 2/2] if -> switch --- pkg/cluster/spec/profile.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/spec/profile.go b/pkg/cluster/spec/profile.go index 2b59532e28..7ad4ba7c5d 100644 --- a/pkg/cluster/spec/profile.go +++ b/pkg/cluster/spec/profile.go @@ -61,11 +61,12 @@ func Initialize(base string) error { tiupData := os.Getenv(tiuplocaldata.EnvNameComponentDataDir) tiupHome := os.Getenv(tiuplocaldata.EnvNameHome) - if tiupData != "" { + switch { + case tiupData != "": profileDir = tiupData - } else if tiupHome != "" { + case tiupHome != "": profileDir = path.Join(tiupHome, tiuplocaldata.StorageParentDir, base) - } else { + default: homeDir, err := getHomeDir() if err != nil { return errors.Trace(err)