Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,23 @@ linters:
- staticcheck
- whitespace
- wrapcheck
- ineffassign
- unused
- unconvert
- bodyclose
- copyloopvar
- nilerr
- nilnil
- wastedassign
- maintidx
- nakedret
- predeclared
- gocritic
- prealloc
exclusions:
Comment thread
obbardc marked this conversation as resolved.
presets:
- comments
formatters:
enable:
- gofmt
- gofumpt
- goimports
6 changes: 4 additions & 2 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ func implementedBackends(m *Machine) []backend {
* "auto" backend chooses them.
*/
func BackendNames() []string {
names := []string{"auto"}
backends := implementedBackends(nil)
names := make([]string, 0, 1+len(backends))
names = append(names, "auto")

for _, backend := range implementedBackends(nil) {
for _, backend := range backends {
names = append(names, backend.Name())
}

Expand Down
14 changes: 9 additions & 5 deletions backend_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (b qemuBackend) ModulePath() (string, error) {
}

func (b qemuBackend) UdevRules() []string {
udevRules := []string{}
udevRules := make([]string, 0, 2*len(b.machine.images))

// create symlink under /dev/disk/by-fakemachine-label/ for each virtual image
for i, img := range b.machine.images {
Expand Down Expand Up @@ -228,14 +228,16 @@ func (b qemuBackend) StartQemu(kvm bool) (bool, error) {
}
memory := fmt.Sprintf("%d", m.memory)
numcpus := fmt.Sprintf("%d", m.numcpus)
qemuargs := []string{qemuMachine.binary,
qemuargs := []string{
qemuMachine.binary,
"-smp", numcpus,
"-m", memory,
"-kernel", kernelPath,
"-initrd", m.initrdpath,
"-display", "none",
"-nic", "user,model=virtio-net-pci",
"-no-reboot"}
"-no-reboot",
}

if kvm {
qemuargs = append(qemuargs,
Expand All @@ -247,9 +249,11 @@ func (b qemuBackend) StartQemu(kvm bool) (bool, error) {

qemuargs = append(qemuargs, "-machine", qemuMachine.machine)
console := fmt.Sprintf("console=%s", qemuMachine.console)
kernelargs := []string{console, "panic=-1",
kernelargs := []string{
console, "panic=-1",
"plymouth.enable=0",
"systemd.unit=fakemachine.service"}
"systemd.unit=fakemachine.service",
}

if m.showBoot {
// Create a character device representing our stdio
Expand Down
20 changes: 12 additions & 8 deletions cmd/fakemachine/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import (
"al.essio.dev/pkg/shellescape"
"errors"
"fmt"
"github.com/docker/go-units"
"github.com/go-debos/fakemachine"
"github.com/jessevdk/go-flags"
"os"
"runtime/debug"
"strings"

"al.essio.dev/pkg/shellescape"

"github.com/docker/go-units"
"github.com/go-debos/fakemachine"
"github.com/jessevdk/go-flags"
)

var Version string
Expand All @@ -28,8 +30,10 @@ type Options struct {
Version bool `long:"version" description:"Print fakemachine version"`
}

var options Options
var parser = flags.NewParser(&options, flags.Default)
var (
options Options
parser = flags.NewParser(&options, flags.Default)
)

func determineVersionFromBuild() string {
info, ok := debug.ReadBuildInfo()
Expand Down Expand Up @@ -131,7 +135,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 environVars = [...]string{
environVars := [...]string{
"http_proxy",
"https_proxy",
"ftp_proxy",
Expand Down Expand Up @@ -166,7 +170,7 @@ func SetupEnviron(m *fakemachine.Machine, options Options) {
}

// Puts in a format that is compatible with output of os.Environ()
EnvironString := []string{}
EnvironString := make([]string, 0, len(EnvironVars))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is prealloc really a useful linter ?

for k, v := range EnvironVars {
warnLocalhost(k, v)
EnvironString = append(EnvironString, fmt.Sprintf("%s=%s", k, v))
Expand Down
11 changes: 6 additions & 5 deletions cpio/writerhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"

"github.com/surma/gocpio"
cpio "github.com/surma/gocpio"
)

type WriterHelper struct {
Expand Down Expand Up @@ -54,7 +54,7 @@ func (w *WriterHelper) ensureBaseDirectory(directory string) error {
continue
}

err := w.WriteDirectory(collector, 0755)
err := w.WriteDirectory(collector, 0o755)
if err != nil {
return err
}
Expand Down Expand Up @@ -184,11 +184,12 @@ func (w *WriterHelper) CopyTree(path string) error {
if err != nil {
return fmt.Errorf("error visiting %s: %w", p, err)
}
if info.Mode().IsDir() {
switch {
case info.Mode().IsDir():
err = w.WriteDirectory(p, info.Mode() & ^os.ModeType)
} else if info.Mode().IsRegular() {
case info.Mode().IsRegular():
err = w.CopyFile(p)
} else {
default:
err = fmt.Errorf("file type not handled for %s", p)
}

Expand Down
2 changes: 1 addition & 1 deletion decompressors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func XzDecompressor(dst io.Writer, src io.Reader) error {
return fmt.Errorf("failed to create xz decompressor: %w", err)
}
// There is no Close() API. See: https://github.com/ulikunitz/xz/issues/45
//defer decompressor.Close()
// defer decompressor.Close()

_, err = io.Copy(dst, decompressor)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion decompressors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path"
"testing"

"github.com/go-debos/fakemachine/cpio"
writerhelper "github.com/go-debos/fakemachine/cpio"
"github.com/stretchr/testify/require"
)

Expand Down
Loading