Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 6515e45

Browse files
author
David Chung
authored
Better handling on platforms where os/user.Current() is not implemented (#294)
Signed-off-by: David Chung <[email protected]>
1 parent 8fa8129 commit 6515e45

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

discovery/discovery.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ func Dir() string {
2626
return pluginDir
2727
}
2828

29-
usr, err := user.Current()
30-
if err != nil {
31-
panic(err)
29+
home := os.Getenv("HOME")
30+
if usr, err := user.Current(); err == nil {
31+
home = usr.HomeDir
3232
}
33-
return path.Join(usr.HomeDir, ".infrakit/plugins")
33+
return path.Join(home, ".infrakit/plugins")
3434
}
3535

3636
// NewPluginDiscovery creates a plugin discovery based on the environment configuration.
3737
func NewPluginDiscovery() (Plugins, error) {
38-
pluginDir := Dir()
38+
return NewPluginDiscoveryWithDirectory(Dir())
39+
}
3940

41+
// NewPluginDiscoveryWithDirectory creates a plugin discovery based on the directory given.
42+
func NewPluginDiscoveryWithDirectory(pluginDir string) (Plugins, error) {
4043
stat, err := os.Stat(pluginDir)
4144
if err == nil {
4245
if !stat.IsDir() {

plugin/flavor/swarm/flavor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ func validateIDsAndAttachments(logicalIDs []instance.LogicalID, attachments map[
5050
idsMap := map[instance.LogicalID]bool{}
5151
for _, id := range logicalIDs {
5252
if _, exists := idsMap[id]; exists {
53-
return fmt.Errorf("LogicalID %s specified more than once", id)
53+
return fmt.Errorf("LogicalID %v specified more than once", id)
5454
}
5555

5656
idsMap[id] = true
5757
}
5858
for id := range attachments {
5959
if _, exists := idsMap[id]; !exists {
60-
return fmt.Errorf("LogicalID %s used for an attachment but is not in group LogicalIDs", id)
60+
return fmt.Errorf("LogicalID %v used for an attachment but is not in group LogicalIDs", id)
6161
}
6262
}
6363

@@ -66,7 +66,7 @@ func validateIDsAndAttachments(logicalIDs []instance.LogicalID, attachments map[
6666
for _, att := range attachments {
6767
for _, attachment := range att {
6868
if _, exists := allAttachments[attachment]; exists {
69-
return fmt.Errorf("Attachment %s specified more than once", attachment)
69+
return fmt.Errorf("Attachment %v specified more than once", attachment)
7070
}
7171
allAttachments[attachment] = true
7272
}

0 commit comments

Comments
 (0)