Skip to content

Commit

Permalink
chore: run gofumpt -w . and go mod tidy
Browse files Browse the repository at this point in the history
`gofumpt` enforces a stricter format than `gofmt`, see more here
https://github.com/mvdan/gofumpt

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee authored and rjoleary committed Dec 2, 2021
1 parent 390845e commit 69bc44b
Show file tree
Hide file tree
Showing 309 changed files with 1,392 additions and 1,435 deletions.
3 changes: 1 addition & 2 deletions cmds/boot/fbnetboot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func boot(ifname string, dhcp dhcpFunc) error {
if filename == "." || filename == "" {
return fmt.Errorf("invalid empty file name extracted from file path %s", u.Path)
}
if err = ioutil.WriteFile(filename, body, 0400); err != nil {
if err = ioutil.WriteFile(filename, body, 0o400); err != nil {
return fmt.Errorf("DHCP: cannot write to file %s: %v", filename, err)
}
debug("DHCP: saved boot file to %s", filename)
Expand Down Expand Up @@ -327,7 +327,6 @@ func loadCaCerts() (*x509.CertPool, error) {
debug("CA certs appended from PEM")
}
return rootCAs, nil

}

func getClientForBootfile(bootfile string) (*http.Client, error) {
Expand Down
6 changes: 4 additions & 2 deletions cmds/contrib/flash/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ type programmer interface {
Close() error
}

type programmerParams map[string]string
type programmerInit func(programmerParams) (programmer, error)
type (
programmerParams map[string]string
programmerInit func(programmerParams) (programmer, error)
)

// supportedProgrammers is populated by the other files in this package.
var supportedProgrammers = map[string]programmerInit{}
Expand Down
1 change: 0 additions & 1 deletion cmds/core/backoff/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestRun(t *testing.T) {
gotErrorString,
wantErrorString)
}

})
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmds/core/basename/basename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type test struct {
}

func TestBasename(t *testing.T) {

var tests = []test{
tests := []test{
{
flags: []string{"foo.h", ".h"},
out: "foo\n",
Expand Down
4 changes: 1 addition & 3 deletions cmds/core/cat/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
"os"
)

var (
_ = flag.Bool("u", false, "ignored")
)
var _ = flag.Bool("u", false, "ignored")

func cat(reader io.Reader, writer io.Writer) error {
if _, err := io.Copy(writer, reader); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmds/core/cat/cat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func setup(t *testing.T, data []byte) (string, error) {

for i, d := range data {
n := fmt.Sprintf("%v%d", filepath.Join(dir, "file"), i)
if err := ioutil.WriteFile(n, []byte{d}, 0666); err != nil {
if err := ioutil.WriteFile(n, []byte{d}, 0o666); err != nil {
return "", err
}
}
Expand Down
15 changes: 7 additions & 8 deletions cmds/core/chmod/chmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func calculateMode(modeString string) (mode os.FileMode, octval uint64, mask uin
var err error
octval, err = strconv.ParseUint(modeString, 8, 32)
if err == nil {
if octval > 0777 {
if octval > 0o777 {
log.Fatalf("Invalid octal value %0o. Value should be less than or equal to 0777.", octval)
}
// a fully described octal mode was supplied, signal that with a special value for mask
Expand Down Expand Up @@ -102,10 +102,10 @@ func calculateMode(modeString string) (mode os.FileMode, octval uint64, mask uin
}

// m[2] is [-+=]
var operator = m[2]
operator := m[2]

// Use a mask so that we do not overwrite permissions for a user/group that was not specified
mask = 0777
mask = 0o777

// For "-", invert octvalDigit before applying the mask
if operator == "-" {
Expand All @@ -115,20 +115,20 @@ func calculateMode(modeString string) (mode os.FileMode, octval uint64, mask uin
// m[1] is [ugoa]+
if strings.Contains(m[1], "o") || strings.Contains(m[1], "a") {
octval += octvalDigit
mask = mask & 0770
mask = mask & 0o770
}
if strings.Contains(m[1], "g") || strings.Contains(m[1], "a") {
octval += octvalDigit << 3
mask = mask & 0707
mask = mask & 0o707
}
if strings.Contains(m[1], "u") || strings.Contains(m[1], "a") {
octval += octvalDigit << 6
mask = mask & 0077
mask = mask & 0o077
}

// For "+" the mask is superfluous, reset it
if operator == "+" {
mask = 0777
mask = 0o777
}

// The mode is fully described, signal that with a special value for mask
Expand Down Expand Up @@ -161,7 +161,6 @@ func main() {
fi, err := os.Stat(reference)
if err != nil {
log.Fatalf("bad reference file: %v", err)

}
mask = special
mode = fi.Mode()
Expand Down
80 changes: 41 additions & 39 deletions cmds/core/chmod/chmod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,34 @@ func TestChmodSimple(t *testing.T) {
defer f.Close()

for k, v := range map[string]fileModeTrans{
"0777": {before: 0000, after: 0777},
"0644": {before: 0777, after: 0644},
"u-rwx": {before: 0777, after: 0077},
"g-rx": {before: 0777, after: 0727},
"a-xr": {before: 0222, after: 0222},
"a-xw": {before: 0666, after: 0444},
"u-xw": {before: 0666, after: 0466},
"a=": {before: 0777, after: 0000},
"u=": {before: 0777, after: 0077},
"u-": {before: 0777, after: 0777},
"o+": {before: 0700, after: 0700},
"g=rx": {before: 0777, after: 0757},
"u=rx": {before: 0077, after: 0577},
"o=rx": {before: 0077, after: 0075},
"u=xw": {before: 0742, after: 0342},
"a-rwx": {before: 0777, after: 0000},
"a-rx": {before: 0777, after: 0222},
"a-x": {before: 0777, after: 0666},
"o+rwx": {before: 0000, after: 0007},
"a+rwx": {before: 0000, after: 0777},
"a+xrw": {before: 0000, after: 0777},
"a+xxxxxxxx": {before: 0000, after: 0111},
"o+xxxxx": {before: 0000, after: 0001},
"a+rx": {before: 0000, after: 0555},
"a+r": {before: 0111, after: 0555},
"a=rwx": {before: 0000, after: 0777},
"a=rx": {before: 0000, after: 0555}} {
"0777": {before: 0o000, after: 0o777},
"0644": {before: 0o777, after: 0o644},
"u-rwx": {before: 0o777, after: 0o077},
"g-rx": {before: 0o777, after: 0o727},
"a-xr": {before: 0o222, after: 0o222},
"a-xw": {before: 0o666, after: 0o444},
"u-xw": {before: 0o666, after: 0o466},
"a=": {before: 0o777, after: 0o000},
"u=": {before: 0o777, after: 0o077},
"u-": {before: 0o777, after: 0o777},
"o+": {before: 0o700, after: 0o700},
"g=rx": {before: 0o777, after: 0o757},
"u=rx": {before: 0o077, after: 0o577},
"o=rx": {before: 0o077, after: 0o075},
"u=xw": {before: 0o742, after: 0o342},
"a-rwx": {before: 0o777, after: 0o000},
"a-rx": {before: 0o777, after: 0o222},
"a-x": {before: 0o777, after: 0o666},
"o+rwx": {before: 0o000, after: 0o007},
"a+rwx": {before: 0o000, after: 0o777},
"a+xrw": {before: 0o000, after: 0o777},
"a+xxxxxxxx": {before: 0o000, after: 0o111},
"o+xxxxx": {before: 0o000, after: 0o001},
"a+rx": {before: 0o000, after: 0o555},
"a+r": {before: 0o111, after: 0o555},
"a=rwx": {before: 0o000, after: 0o777},
"a=rx": {before: 0o000, after: 0o555},
} {
// Set up the 'before' state
err := os.Chmod(f.Name(), v.before)
if err != nil {
Expand Down Expand Up @@ -106,7 +107,8 @@ func TestChmodRecursive(t *testing.T) {
defer os.RemoveAll(tempDir)

var targetDirectories []string
for _, dir := range []string{"L1_A", "L1_B", "L1_C",
for _, dir := range []string{
"L1_A", "L1_B", "L1_C",
filepath.Join("L1_A", "L2_A"),
filepath.Join("L1_A", "L2_B"),
filepath.Join("L1_A", "L2_C"),
Expand All @@ -118,22 +120,23 @@ func TestChmodRecursive(t *testing.T) {
filepath.Join("L1_C", "L2_C"),
} {
dir = filepath.Join(tempDir, dir)
err := os.Mkdir(dir, os.FileMode(0700))
err := os.Mkdir(dir, os.FileMode(0o700))
if err != nil {
t.Fatalf("cannot create test directory: %v", err)
}
targetDirectories = append(targetDirectories, dir)
}

for k, v := range map[string]fileModeTrans{
"0707": {before: 0755, after: 0707},
"0770": {before: 0755, after: 0770},
"o-rwx": {before: 0777, after: 0770},
"g-rx": {before: 0777, after: 0727},
"a=rrrrrwx": {before: 0777, after: 0777},
"a+w": {before: 0700, after: 0722},
"g+xr": {before: 0700, after: 0750},
"a=rx": {before: 0777, after: 0555}} {
"0707": {before: 0o755, after: 0o707},
"0770": {before: 0o755, after: 0o770},
"o-rwx": {before: 0o777, after: 0o770},
"g-rx": {before: 0o777, after: 0o727},
"a=rrrrrwx": {before: 0o777, after: 0o777},
"a+w": {before: 0o700, after: 0o722},
"g+xr": {before: 0o700, after: 0o750},
"a=rx": {before: 0o777, after: 0o555},
} {

// Set up the 'before' state
for _, dir := range targetDirectories {
Expand Down Expand Up @@ -177,7 +180,7 @@ func TestChmodReference(t *testing.T) {
}
defer targetFile.Close()

for _, perm := range []os.FileMode{0777, 0644} {
for _, perm := range []os.FileMode{0o777, 0o644} {
err = os.Chmod(sourceFile.Name(), perm)
if err != nil {
t.Fatalf("chmod(%q) failed: %v", sourceFile.Name(), err)
Expand Down Expand Up @@ -224,7 +227,6 @@ func TestInvocationErrors(t *testing.T) {
skipTo int
skipFrom int
}{

{
args: []string{f.Name()},
want: "Usage",
Expand Down
2 changes: 0 additions & 2 deletions cmds/core/chroot/chroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestUserSpecString(t *testing.T) {
if str != input {
t.Errorf("Unexpected error with input: %s, String method returned: %s", input, str)
}

}

func testGroupSet(input string, expected []uint32) error {
Expand Down Expand Up @@ -127,5 +126,4 @@ func TestGroupsSet(t *testing.T) {
if err = testGroupSet(input, expected); err == nil {
t.Errorf("Expected error on input: %s, got: %v", input, groups.groups)
}

}
6 changes: 2 additions & 4 deletions cmds/core/cmp/cmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import (
)

func TestEmit(t *testing.T) {

var buf = []byte("hello\nthis is a test\n")
var buf2 = []byte("hello\nthiz is a text")
buf := []byte("hello\nthis is a test\n")
buf2 := []byte("hello\nthiz is a text")

c1 := make(chan byte, 8192)
c2 := make(chan byte, 8192)
Expand All @@ -36,5 +35,4 @@ func TestEmit(t *testing.T) {
if err != io.EOF {
t.Errorf("%v", err)
}

}
2 changes: 1 addition & 1 deletion cmds/core/comm/comm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestComm(t *testing.T) {
var files [2]string
for i, contents := range []string{test.in1, test.in2} {
files[i] = filepath.Join(tmpDir, fmt.Sprintf("txt%d", i))
if err := ioutil.WriteFile(files[i], []byte(contents), 0600); err != nil {
if err := ioutil.WriteFile(files[i], []byte(contents), 0o600); err != nil {
t.Fatalf("Failed to create test file %d: %v", i, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmds/core/cp/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ func TestCpRecursive(t *testing.T) {
defer os.RemoveAll(tempDir)

srcDir := filepath.Join(tempDir, "src")
if err := os.Mkdir(srcDir, 0755); err != nil {
if err := os.Mkdir(srcDir, 0o755); err != nil {
t.Fatal(err)
}
dstDir := filepath.Join(tempDir, "dst-exists")
if err := os.Mkdir(dstDir, 0755); err != nil {
if err := os.Mkdir(dstDir, 0o755); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func TestCpRecursiveMultiple(t *testing.T) {
defer os.RemoveAll(tempDir)

dstTest := filepath.Join(tempDir, "destination")
if err := os.Mkdir(dstTest, 0755); err != nil {
if err := os.Mkdir(dstTest, 0o755); err != nil {
t.Fatalf("Failed on build directory %v: %v", dstTest, err)
}

Expand Down
10 changes: 5 additions & 5 deletions cmds/core/cpio/cpio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestCpio(t *testing.T) {
}
defer os.RemoveAll(tempDir)

var targets = []dirEnt{
targets := []dirEnt{
{Name: "file1", Type: "file", Content: "Hello World"},
{Name: "file2", Type: "file", Content: ""},
{Name: "directory1", Type: "dir"},
Expand All @@ -44,10 +44,10 @@ func TestCpio(t *testing.T) {
}...)
}
for _, ent := range targets {
var name = filepath.Join(tempDir, ent.Name)
name := filepath.Join(tempDir, ent.Name)
switch ent.Type {
case "dir":
err := os.Mkdir(name, os.FileMode(0700))
err := os.Mkdir(name, os.FileMode(0o700))
if err != nil {
t.Fatalf("cannot create test directory: %v", err)
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestCpio(t *testing.T) {
// the FileInfo for each target. This needs to happen in a second
// pass because of the link count.
for key, ent := range targets {
var name = filepath.Join(tempDir, ent.Name)
name := filepath.Join(tempDir, ent.Name)
targets[key].FileInfo, err = os.Stat(name)
if err != nil {
t.Fatalf("cannot stat temporary dirent: %v", err)
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestCpio(t *testing.T) {
}

for _, ent := range targets {
var name = filepath.Join(tempExtractDir, ent.Name)
name := filepath.Join(tempExtractDir, ent.Name)
newFileInfo, err := os.Stat(name)
if err != nil {
t.Error(err)
Expand Down
4 changes: 2 additions & 2 deletions cmds/core/cpio/testdata/dir-hard-link.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func main() {
}
rw := archiver.Writer(os.Stdout)
for _, rec := range []cpio.Record{
cpio.Directory("directory1", 0755),
cpio.Directory("directory2", 0755),
cpio.Directory("directory1", 0o755),
cpio.Directory("directory2", 0o755),
} {
rec.UID = uint64(os.Getuid())
rec.GID = uint64(os.Getgid())
Expand Down
3 changes: 1 addition & 2 deletions cmds/core/date/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func TestDateNoFlags(t *testing.T) {
if d != dTest {
t.Errorf("Mismatched dates; want %v, got %v\n", d, dTest)
}

}

// using u flag
Expand Down Expand Up @@ -74,7 +73,7 @@ func TestDateMapExamples(t *testing.T) {
example string // correct example
}

var tests = []dateTest{
tests := []dateTest{
{
"%a %b %e %H:%M:%S %Z %Y",
"Tue Jun 26 09:58:10 PDT 1990",
Expand Down
2 changes: 1 addition & 1 deletion cmds/core/dd/dd.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func outFile(name string, outputBytes int64, seek int64, flags int) (io.Writer,
out = os.Stdout
} else {
perm := os.O_CREATE | os.O_WRONLY | (flags & allowedFlags)
if out, err = os.OpenFile(name, perm, 0666); err != nil {
if out, err = os.OpenFile(name, perm, 0o666); err != nil {
return nil, fmt.Errorf("error opening output file %q: %v", name, err)
}
}
Expand Down
Loading

0 comments on commit 69bc44b

Please sign in to comment.