Skip to content

Commit

Permalink
Run gofmt -ws on the codebase
Browse files Browse the repository at this point in the history
Formatting wasn't consistent unfortunately, so do a gofmt pass to correct
that.

Signed-off-by: Sjoerd Simons <[email protected]>
  • Loading branch information
sjoerdsimons committed Apr 13, 2022
1 parent 0ef6635 commit cb6e194
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 47 deletions.
6 changes: 3 additions & 3 deletions backend.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// +build linux
// +build amd64
//go:build linux && amd64
// +build linux,amd64

package fakemachine

import(
import (
"fmt"
)

Expand Down
10 changes: 5 additions & 5 deletions backend_qemu.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build linux
// +build amd64
//go:build linux && amd64
// +build linux,amd64

package fakemachine

Expand Down Expand Up @@ -59,7 +59,7 @@ func (b qemuBackend) KernelRelease() (string, error) {
return "", err
}

for i := len(files)-1; i >= 0; i-- {
for i := len(files) - 1; i >= 0; i-- {
/* Ensure the kernel name starts with a digit, in order
* to filter out 'extramodules-ARCH' on ArchLinux */
filename := files[i].Name()
Expand Down Expand Up @@ -183,8 +183,8 @@ func (b qemuBackend) StartQemu(kvm bool) (bool, error) {

if kvm {
qemuargs = append(qemuargs,
"-cpu", "host",
"-enable-kvm")
"-cpu", "host",
"-enable-kvm")
}

kernelargs := []string{"console=ttyS0", "panic=-1",
Expand Down
10 changes: 4 additions & 6 deletions backend_uml.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build linux
// +build amd64
//go:build linux && amd64
// +build linux,amd64

package fakemachine

Expand Down Expand Up @@ -173,10 +173,9 @@ func (b umlBackend) Start() (bool, error) {
}
defer umlVectorTransportSocket.Close()


// launch libslirp-helper
slirpHelperArgs := []string{"libslirp-helper",
"--exit-with-parent"}
"--exit-with-parent"}

/* attach the slirpHelperSocket as an additional fd to the process,
* after std*. The helper then bridges the host network to the attached
Expand All @@ -195,7 +194,6 @@ func (b umlBackend) Start() (bool, error) {
}
defer slirpHelper.Kill()


// launch uml guest
memory := fmt.Sprintf("%d", m.memory)
umlargs := []string{"linux",
Expand Down Expand Up @@ -232,7 +230,7 @@ func (b umlBackend) Start() (bool, error) {
umlargs = append(umlargs,
"con1=fd:0,fd:1",
"con0=null",
"con=none") // no other consoles
"con=none") // no other consoles
}

for i, img := range m.images {
Expand Down
20 changes: 10 additions & 10 deletions cmd/fakemachine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

type Options struct {
Backend string `short:"b" long:"backend" description:"Virtualisation backend to use" default:"auto"`
Volumes []string `short:"v" long:"volume" description:"volume to mount"`
Images []string `short:"i" long:"image" description:"image to add"`
Backend string `short:"b" long:"backend" description:"Virtualisation backend to use" default:"auto"`
Volumes []string `short:"v" long:"volume" description:"volume to mount"`
Images []string `short:"i" long:"image" description:"image to add"`
EnvironVars map[string]string `short:"e" long:"environ-var" description:"Environment variables (use -e VARIABLE:VALUE syntax)"`
Memory int `short:"m" long:"memory" description:"Amount of memory for the fakemachine in megabytes"`
CPUs int `short:"c" long:"cpus" description:"Number of CPUs for the fakemachine"`
ScratchSize string `short:"s" long:"scratchsize" description:"On-disk scratch space size (with a unit suffix, e.g. 4G); if unset, memory backed scratch space is used"`
ShowBoot bool `long:"show-boot" description:"Show boot/console messages from the fakemachine"`
Memory int `short:"m" long:"memory" description:"Amount of memory for the fakemachine in megabytes"`
CPUs int `short:"c" long:"cpus" description:"Number of CPUs for the fakemachine"`
ScratchSize string `short:"s" long:"scratchsize" description:"On-disk scratch space size (with a unit suffix, e.g. 4G); if unset, memory backed scratch space is used"`
ShowBoot bool `long:"show-boot" description:"Show boot/console messages from the fakemachine"`
}

var options Options
Expand All @@ -29,8 +29,8 @@ func warnLocalhost(variable string, value string) {
Consider using an address that is valid on your network.`

if strings.Contains(value, "localhost") ||
strings.Contains(value, "127.0.0.1") ||
strings.Contains(value, "::1") {
strings.Contains(value, "127.0.0.1") ||
strings.Contains(value, "::1") {
fmt.Printf(message, variable)
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func SetupEnviron(m *fakemachine.Machine, options Options) {
// These are the environment variables that will be detected on the
// host and propagated to fakemachine. These are listed lower case, but
// they are detected and configured in both lower case and upper case.
var environ_vars = [...]string {
var environ_vars = [...]string{
"http_proxy",
"https_proxy",
"ftp_proxy",
Expand Down
2 changes: 1 addition & 1 deletion decompressors.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package fakemachine

import (
"io"
"compress/gzip"
"io"

"github.com/klauspost/compress/zstd"
"github.com/ulikunitz/xz"
Expand Down
2 changes: 1 addition & 1 deletion decompressors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func checkStreamsMatch(t *testing.T, output, check io.Reader) error {
}

func decompressorTest(t *testing.T, file, suffix string, d writerhelper.Transformer) {
f, err := os.Open(path.Join("testdata", file + suffix))
f, err := os.Open(path.Join("testdata", file+suffix))
if err != nil {
t.Errorf("Unable to open test data: %s", err)
return
Expand Down
41 changes: 20 additions & 21 deletions machine.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build linux
// +build amd64
//go:build linux && amd64
// +build linux,amd64

package fakemachine

Expand Down Expand Up @@ -56,7 +56,7 @@ func getModData(modname string, fieldname string, kernelRelease string) []string
// Get full path of module
func getModPath(modname string, kernelRelease string) string {
path := getModData(modname, "filename", kernelRelease)
if len(path) != 0 {
if len(path) != 0 {
return path[0]
}
return ""
Expand All @@ -67,7 +67,7 @@ func getModDepends(modname string, kernelRelease string) []string {
deplist := getModData(modname, "depends", kernelRelease)
var modlist []string
for _, v := range deplist {
if v != "" {
if v != "" {
modlist = append(modlist, strings.Split(v, ",")...)
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func (m *Machine) copyModules(w *writerhelper.WriterHelper, modname string, suff
// The suffix is the complete thing - ".ko.foobar"
// Reinstate the required ".ko" part, after trimming.
basepath := strings.TrimSuffix(modpath, suffix) + ".ko"
if err := w.TransformFileTo(modpath, prefix + basepath, fn); err != nil {
if err := w.TransformFileTo(modpath, prefix+basepath, fn); err != nil {
return err
}
found = true
Expand All @@ -114,7 +114,7 @@ func (m *Machine) copyModules(w *writerhelper.WriterHelper, modname string, suff
return errors.New("Module extension/suffix unknown")
}

copiedModules[modname] = true;
copiedModules[modname] = true

deplist := getModDepends(modname, release)
for _, mod := range deplist {
Expand Down Expand Up @@ -332,7 +332,7 @@ func tmplStaticVolumes(m Machine) []mountPoint {

func executeInitScriptTemplate(m *Machine, b backend) ([]byte, error) {
helperFuncs := template.FuncMap{
"MountVolume": tmplMountVolume,
"MountVolume": tmplMountVolume,
"StaticVolumes": tmplStaticVolumes,
}

Expand Down Expand Up @@ -478,7 +478,7 @@ func (m Machine) generateFstab(w *writerhelper.WriterHelper, backend backend) {
}

func stripModuleSuffixes(module string, suffixes []string) (string, error) {
for _, suffix := range(suffixes) {
for _, suffix := range suffixes {
if strings.HasSuffix(module, suffix) {
// The suffix is the complete thing - ".ko.foobar"
// Reinstate the required ".ko" part, after trimming.
Expand All @@ -501,8 +501,8 @@ func (m *Machine) generateModulesDep(w *writerhelper.WriterHelper, moddir string
output := make([]string, len(keys))
release, _ := m.backend.KernelRelease()
for i, k := range keys {
modpath, _ := stripModuleSuffixes(getModPath(k, release), suffixes) // CANNOT fail
deplist := getModDepends(k, release) // CANNOT fail
modpath, _ := stripModuleSuffixes(getModPath(k, release), suffixes) // CANNOT fail
deplist := getModDepends(k, release) // CANNOT fail
deps := make([]string, len(deplist))
for j, mod := range deplist {
deppath, _ := stripModuleSuffixes(getModPath(mod, release), suffixes) // CANNOT fail
Expand All @@ -519,23 +519,22 @@ func (m *Machine) SetEnviron(environ []string) {
m.Environ = environ
}


func (m *Machine) writerKernelModules(w *writerhelper.WriterHelper, moddir string, modules []string) error {
suffixes := map[string]writerhelper.Transformer {
".ko": NullDecompressor,
".ko.gz": GzipDecompressor,
".ko.xz": XzDecompressor,
suffixes := map[string]writerhelper.Transformer{
".ko": NullDecompressor,
".ko.gz": GzipDecompressor,
".ko.xz": XzDecompressor,
".ko.zst": ZstdDecompressor,
}

if len(modules) == 0 {
return nil
}

modfiles := []string {
"modules.builtin",
"modules.alias",
"modules.symbols"}
modfiles := []string{
"modules.builtin",
"modules.alias",
"modules.symbols"}

for _, v := range modfiles {
if err := w.CopyFile(moddir + "/" + v); err != nil {
Expand All @@ -545,7 +544,7 @@ func (m *Machine) writerKernelModules(w *writerhelper.WriterHelper, moddir strin

copiedModules := make(map[string]bool)

for _, modname := range modules {
for _, modname := range modules {
if err := m.copyModules(w, modname, suffixes, copiedModules); err != nil {
return err
}
Expand Down Expand Up @@ -596,7 +595,7 @@ func (m *Machine) cleanup() {
func (m *Machine) startup(command string, extracontent [][2]string) (int, error) {
defer m.cleanup()

os.Setenv("PATH", os.Getenv("PATH") + ":/sbin:/usr/sbin")
os.Setenv("PATH", os.Getenv("PATH")+":/sbin:/usr/sbin")

tmpdir, err := ioutil.TempDir("", "fakemachine-")
if err != nil {
Expand Down

0 comments on commit cb6e194

Please sign in to comment.