-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move non windows additional notes to new file
- Loading branch information
1 parent
e8d389f
commit 9d19a83
Showing
3 changed files
with
104 additions
and
54 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package plugin | ||
|
||
import ( | ||
"debug/elf" | ||
"debug/macho" | ||
"debug/pe" | ||
"fmt" | ||
"os" | ||
"os/user" | ||
"runtime" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose | ||
// why it won't run correctly. It runs as a best effort only. | ||
func additionalNotesAboutCommand(path string) string { | ||
notes := "" | ||
stat, err := os.Stat(path) | ||
if err != nil { | ||
return notes | ||
} | ||
|
||
notes += "\nAdditional notes about plugin:\n" | ||
notes += fmt.Sprintf(" Path: %s\n", path) | ||
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode()) | ||
statT, ok := stat.Sys().(*syscall.Stat_t) | ||
if ok { | ||
currentUsername := "?" | ||
if u, err := user.LookupId(strconv.FormatUint(uint64(os.Getuid()), 10)); err == nil { | ||
currentUsername = u.Username | ||
} | ||
currentGroup := "?" | ||
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(os.Getgid()), 10)); err == nil { | ||
currentGroup = g.Name | ||
} | ||
username := "?" | ||
if u, err := user.LookupId(strconv.FormatUint(uint64(statT.Uid), 10)); err == nil { | ||
username = u.Username | ||
} | ||
group := "?" | ||
if g, err := user.LookupGroupId(strconv.FormatUint(uint64(statT.Gid), 10)); err == nil { | ||
group = g.Name | ||
} | ||
notes += fmt.Sprintf(" Owner: %d [%s] (current: %d [%s])\n", statT.Uid, username, os.Getuid(), currentUsername) | ||
notes += fmt.Sprintf(" Group: %d [%s] (current: %d [%s])\n", statT.Gid, group, os.Getgid(), currentGroup) | ||
} | ||
|
||
if elfFile, err := elf.Open(path); err == nil { | ||
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH) | ||
} else if machoFile, err := macho.Open(path); err == nil { | ||
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH) | ||
} else if peFile, err := pe.Open(path); err == nil { | ||
machine, ok := peTypes[peFile.Machine] | ||
if !ok { | ||
machine = "unknown" | ||
} | ||
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH) | ||
} | ||
return notes | ||
} |
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,40 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package plugin | ||
|
||
import ( | ||
"debug/elf" | ||
"debug/macho" | ||
"debug/pe" | ||
"fmt" | ||
"os" | ||
"runtime" | ||
) | ||
|
||
// additionalNotesAboutCommand tries to get additional information about a command that might help diagnose | ||
// why it won't run correctly. It runs as a best effort only. | ||
func additionalNotesAboutCommand(path string) string { | ||
notes := "" | ||
stat, err := os.Stat(path) | ||
if err != nil { | ||
return notes | ||
} | ||
|
||
notes += "\nAdditional notes about plugin:\n" | ||
notes += fmt.Sprintf(" Path: %s\n", path) | ||
notes += fmt.Sprintf(" Mode: %s\n", stat.Mode()) | ||
|
||
if elfFile, err := elf.Open(path); err == nil { | ||
notes += fmt.Sprintf(" ELF architecture: %s (current architecture: %s)\n", elfFile.Machine, runtime.GOARCH) | ||
} else if machoFile, err := macho.Open(path); err == nil { | ||
notes += fmt.Sprintf(" MachO architecture: %s (current architecture: %s)\n", machoFile.Cpu, runtime.GOARCH) | ||
} else if peFile, err := pe.Open(path); err == nil { | ||
machine, ok := peTypes[peFile.Machine] | ||
if !ok { | ||
machine = "unknown" | ||
} | ||
notes += fmt.Sprintf(" PE architecture: %s (current architecture: %s)\n", machine, runtime.GOARCH) | ||
} | ||
return notes | ||
} |