Skip to content

Commit a151311

Browse files
committed
fix: list keys with relative paths
1 parent 7735daf commit a151311

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

utils.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,12 @@ func CreateLink(alias string, keyMap map[string]*SSHKey, env *Environment) {
176176
if !found {
177177
return
178178
}
179+
179180
relStorePath, err := filepath.Rel(env.SSHPath, env.StorePath)
180181
if err != nil {
181182
fmt.Println("Failed to find rel store path")
182183
}
184+
183185
//Create symlink for private key
184186
if err := os.Symlink(filepath.Join(relStorePath, alias, key.Type.PrivateKey()), filepath.Join(env.SSHPath, key.Type.PrivateKey())); err != nil {
185187
fmt.Println("Failed to create symble link for private key")
@@ -196,7 +198,7 @@ func CreateLink(alias string, keyMap map[string]*SSHKey, env *Environment) {
196198
func loadSingleKey(keyPath string, env *Environment) *SSHKey {
197199
key := &SSHKey{}
198200

199-
//Walkthrough SSH key store and load all the keys
201+
//Walk-through SSH key store and load all the keys
200202
err := filepath.Walk(keyPath, func(path string, f os.FileInfo, err error) error {
201203
if f == nil {
202204
return err
@@ -224,7 +226,13 @@ func loadSingleKey(keyPath string, env *Environment) *SSHKey {
224226
//Check if key is in use
225227
key.PrivateKey = path
226228

227-
if path == ParsePath(filepath.Join(env.SSHPath, kt.KeyBaseName)) {
229+
parsedPath := ParsePath(filepath.Join(env.SSHPath, kt.KeyBaseName))
230+
absPath, err := filepath.Abs(filepath.Join(env.SSHPath, parsedPath))
231+
if err != nil {
232+
return nil
233+
}
234+
235+
if path == absPath {
228236
key.IsDefault = true
229237
}
230238

@@ -268,7 +276,7 @@ func ParsePath(path string) string {
268276
func LoadSSHKeys(env *Environment) map[string]*SSHKey {
269277
keys := map[string]*SSHKey{}
270278

271-
//Walkthrough SSH key store and load all the keys
279+
//Walk-through SSH key store and load all the keys
272280
err := filepath.Walk(env.StorePath, func(path string, f os.FileInfo, err error) error {
273281
if f == nil {
274282
return err

0 commit comments

Comments
 (0)