Skip to content

Commit 7dc9726

Browse files
authored
Merge pull request #227 from hashicorp/fix-win-build
fix windows build: move additional notes to new files
2 parents 06d4d53 + 9d19a83 commit 7dc9726

File tree

3 files changed

+104
-54
lines changed

3 files changed

+104
-54
lines changed

client.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import (
66
"crypto/subtle"
77
"crypto/tls"
88
"crypto/x509"
9-
"debug/elf"
10-
"debug/macho"
11-
"debug/pe"
129
"encoding/base64"
1310
"errors"
1411
"fmt"
@@ -18,14 +15,11 @@ import (
1815
"net"
1916
"os"
2017
"os/exec"
21-
"os/user"
2218
"path/filepath"
23-
"runtime"
2419
"strconv"
2520
"strings"
2621
"sync"
2722
"sync/atomic"
28-
"syscall"
2923
"time"
3024

3125
"github.com/hashicorp/go-hclog"
@@ -497,54 +491,6 @@ var peTypes = map[uint16]string{
497491
0xaa64: "arm64",
498492
}
499493

500-
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
501-
// why it won't run correctly. It runs as a best effort only.
502-
func additionalNotesAboutCommand(path string) string {
503-
notes := ""
504-
stat, err := os.Stat(path)
505-
if err != nil {
506-
return notes
507-
}
508-
509-
notes += "\nAdditional notes about plugin:\n"
510-
notes += fmt.Sprintf(" Path: %s\n", path)
511-
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
512-
statT, ok := stat.Sys().(*syscall.Stat_t)
513-
if ok {
514-
currentUsername := "?"
515-
if u, err := user.LookupId(strconv.FormatUint(uint64(os.Getuid()), 10)); err == nil {
516-
currentUsername = u.Username
517-
}
518-
currentGroup := "?"
519-
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(os.Getgid()), 10)); err == nil {
520-
currentGroup = g.Name
521-
}
522-
username := "?"
523-
if u, err := user.LookupId(strconv.FormatUint(uint64(statT.Uid), 10)); err == nil {
524-
username = u.Username
525-
}
526-
group := "?"
527-
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(statT.Gid), 10)); err == nil {
528-
group = g.Name
529-
}
530-
notes += fmt.Sprintf(" Owner: %d [%s] (current: %d [%s])\n", statT.Uid, username, os.Getuid(), currentUsername)
531-
notes += fmt.Sprintf(" Group: %d [%s] (current: %d [%s])\n", statT.Gid, group, os.Getgid(), currentGroup)
532-
}
533-
534-
if elfFile, err := elf.Open(path); err == nil {
535-
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
536-
} else if machoFile, err := macho.Open(path); err == nil {
537-
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
538-
} else if peFile, err := pe.Open(path); err == nil {
539-
machine, ok := peTypes[peFile.Machine]
540-
if !ok {
541-
machine = "unknown"
542-
}
543-
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
544-
}
545-
return notes
546-
}
547-
548494
// Start the underlying subprocess, communicating with it to negotiate
549495
// a port for RPC connections, and returning the address to connect via RPC.
550496
//

notes_unix.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package plugin
5+
6+
import (
7+
"debug/elf"
8+
"debug/macho"
9+
"debug/pe"
10+
"fmt"
11+
"os"
12+
"os/user"
13+
"runtime"
14+
"strconv"
15+
"syscall"
16+
)
17+
18+
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
19+
// why it won't run correctly. It runs as a best effort only.
20+
func additionalNotesAboutCommand(path string) string {
21+
notes := ""
22+
stat, err := os.Stat(path)
23+
if err != nil {
24+
return notes
25+
}
26+
27+
notes += "\nAdditional notes about plugin:\n"
28+
notes += fmt.Sprintf(" Path: %s\n", path)
29+
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
30+
statT, ok := stat.Sys().(*syscall.Stat_t)
31+
if ok {
32+
currentUsername := "?"
33+
if u, err := user.LookupId(strconv.FormatUint(uint64(os.Getuid()), 10)); err == nil {
34+
currentUsername = u.Username
35+
}
36+
currentGroup := "?"
37+
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(os.Getgid()), 10)); err == nil {
38+
currentGroup = g.Name
39+
}
40+
username := "?"
41+
if u, err := user.LookupId(strconv.FormatUint(uint64(statT.Uid), 10)); err == nil {
42+
username = u.Username
43+
}
44+
group := "?"
45+
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(statT.Gid), 10)); err == nil {
46+
group = g.Name
47+
}
48+
notes += fmt.Sprintf(" Owner: %d [%s] (current: %d [%s])\n", statT.Uid, username, os.Getuid(), currentUsername)
49+
notes += fmt.Sprintf(" Group: %d [%s] (current: %d [%s])\n", statT.Gid, group, os.Getgid(), currentGroup)
50+
}
51+
52+
if elfFile, err := elf.Open(path); err == nil {
53+
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
54+
} else if machoFile, err := macho.Open(path); err == nil {
55+
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
56+
} else if peFile, err := pe.Open(path); err == nil {
57+
machine, ok := peTypes[peFile.Machine]
58+
if !ok {
59+
machine = "unknown"
60+
}
61+
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
62+
}
63+
return notes
64+
}

notes_windows.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package plugin
5+
6+
import (
7+
"debug/elf"
8+
"debug/macho"
9+
"debug/pe"
10+
"fmt"
11+
"os"
12+
"runtime"
13+
)
14+
15+
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose
16+
// why it won't run correctly. It runs as a best effort only.
17+
func additionalNotesAboutCommand(path string) string {
18+
notes := ""
19+
stat, err := os.Stat(path)
20+
if err != nil {
21+
return notes
22+
}
23+
24+
notes += "\nAdditional notes about plugin:\n"
25+
notes += fmt.Sprintf(" Path: %s\n", path)
26+
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode())
27+
28+
if elfFile, err := elf.Open(path); err == nil {
29+
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH)
30+
} else if machoFile, err := macho.Open(path); err == nil {
31+
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH)
32+
} else if peFile, err := pe.Open(path); err == nil {
33+
machine, ok := peTypes[peFile.Machine]
34+
if !ok {
35+
machine = "unknown"
36+
}
37+
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH)
38+
}
39+
return notes
40+
}

0 commit comments

Comments
 (0)