-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: kcl lib home and install lock
Signed-off-by: peefy <[email protected]>
- Loading branch information
Showing
20 changed files
with
179 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA= | ||
github.com/ebitengine/purego v0.7.1/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ= | ||
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E= | ||
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0= | ||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= | ||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= | ||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= | ||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright The KCL Authors. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Reference: k8s.io/client-go/util/homedir | ||
package path | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
) | ||
|
||
// HomeDir returns the home directory for the current user. | ||
// On Windows: | ||
// 1. if none of those locations are writeable, the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that exists is returned. | ||
// 2. if none of those locations exists, the first of %HOME%, %USERPROFILE%, %HOMEDRIVE%%HOMEPATH% that is set is returned. | ||
func HomeDir() string { | ||
if runtime.GOOS == "windows" { | ||
home := os.Getenv("HOME") | ||
homeDriveHomePath := "" | ||
if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 { | ||
homeDriveHomePath = homeDrive + homePath | ||
} | ||
userProfile := os.Getenv("USERPROFILE") | ||
|
||
firstSetPath := "" | ||
firstExistingPath := "" | ||
|
||
// Prefer %USERPROFILE% over %HOMEDRIVE%/%HOMEPATH% for compatibility with other auth-writing tools | ||
for _, p := range []string{home, userProfile, homeDriveHomePath} { | ||
if len(p) == 0 { | ||
continue | ||
} | ||
if len(firstSetPath) == 0 { | ||
// remember the first path that is set | ||
firstSetPath = p | ||
} | ||
info, err := os.Stat(p) | ||
if err != nil { | ||
continue | ||
} | ||
if len(firstExistingPath) == 0 { | ||
// remember the first path that exists | ||
firstExistingPath = p | ||
} | ||
if info.IsDir() && info.Mode().Perm()&(1<<(uint(7))) != 0 { | ||
// return first path that is writeable | ||
return p | ||
} | ||
} | ||
|
||
// If none are writeable, return first location that exists | ||
if len(firstExistingPath) > 0 { | ||
return firstExistingPath | ||
} | ||
|
||
// If none exist, return first location that is set | ||
if len(firstSetPath) > 0 { | ||
return firstSetPath | ||
} | ||
|
||
// We've got nothing | ||
return "" | ||
} | ||
return os.Getenv("HOME") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build darwin | ||
// +build darwin | ||
|
||
package path | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
// DataHome defines the base directory relative to which user specific data files should be stored. | ||
func DataHome() string { | ||
return filepath.Join(HomeDir(), "Library") | ||
} | ||
|
||
// ConfigHome defines the base directory relative to which user specific configuration files should | ||
// be stored. | ||
func ConfigHome() string { | ||
return filepath.Join(HomeDir(), "Library", "Preferences") | ||
} | ||
|
||
// CacheHome defines the base directory relative to which user specific non-essential data files | ||
// should be stored. | ||
func CacheHome() string { | ||
return filepath.Join(HomeDir(), "Library", "Caches") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build !windows && !darwin | ||
// +build !windows,!darwin | ||
|
||
package path | ||
|
||
import ( | ||
"path/filepath" | ||
) | ||
|
||
// DataHome defines the base directory relative to which user specific data files should be stored. | ||
func DataHome() string { | ||
return filepath.Join(HomeDir(), ".local", "share") | ||
} | ||
|
||
// ConfigHome defines the base directory relative to which user specific configuration files should | ||
// be stored. | ||
func ConfigHome() string { | ||
return filepath.Join(HomeDir(), ".config") | ||
} | ||
|
||
// CacheHome defines the base directory relative to which user specific non-essential data files | ||
// should be stored. | ||
func CacheHome() string { | ||
return filepath.Join(HomeDir(), ".cache") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package path | ||
|
||
import "os" | ||
|
||
// DataHome defines the base directory relative to which user specific data files should be stored. | ||
func DataHome() string { | ||
return ConfigHome() | ||
} | ||
|
||
// ConfigHome defines the base directory relative to which user specific configuration files should | ||
// be stored. | ||
func ConfigHome() string { | ||
return os.Getenv("APPDATA") | ||
} | ||
|
||
// CacheHome defines the base directory relative to which user specific non-essential data files | ||
// should be stored. | ||
func CacheHome() string { | ||
return os.Getenv("TEMP") | ||
} |