Skip to content

Commit f5d245e

Browse files
committed
format code with gofumpt
gofumpt (https://github.com/mvdan/gofumpt) provides a superset of Go's gofmt. While slightly more strict, it also helps some formatting issues that linters (such as "revive") may trip over, so let's do a one-time format of the code with gofumpt. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b4ca352 commit f5d245e

22 files changed

Lines changed: 226 additions & 245 deletions

cmd/continuity/commands/ls.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ var LSCmd = &cobra.Command{
5050
//nolint:unconvert
5151
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", os.FileMode(entry.Mode), entry.User, entry.Group, humanize.Bytes(uint64(entry.Size)), path)
5252
}
53-
5453
}
5554
}
5655

cmd/continuity/commands/stats.go

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,48 @@ import (
2525
"github.com/spf13/cobra"
2626
)
2727

28-
var (
29-
StatsCmd = &cobra.Command{
30-
Use: "stats <manifest>",
31-
Short: "display statistics about the specified manifest",
32-
Run: func(cmd *cobra.Command, args []string) {
33-
if len(args) != 1 {
34-
log.Fatalln("please specify a manifest")
35-
}
28+
var StatsCmd = &cobra.Command{
29+
Use: "stats <manifest>",
30+
Short: "display statistics about the specified manifest",
31+
Run: func(cmd *cobra.Command, args []string) {
32+
if len(args) != 1 {
33+
log.Fatalln("please specify a manifest")
34+
}
3635

37-
bm, err := readManifestFile(args[0])
38-
if err != nil {
39-
log.Fatalf("error reading manifest: %v", err)
40-
}
36+
bm, err := readManifestFile(args[0])
37+
if err != nil {
38+
log.Fatalf("error reading manifest: %v", err)
39+
}
4140

42-
var stats struct {
43-
resources int
44-
files int
45-
directories int
46-
totalSize int64
47-
symlinks int
48-
}
41+
var stats struct {
42+
resources int
43+
files int
44+
directories int
45+
totalSize int64
46+
symlinks int
47+
}
4948

50-
for _, entry := range bm.Resource {
51-
stats.resources++
52-
stats.totalSize += int64(entry.Size)
49+
for _, entry := range bm.Resource {
50+
stats.resources++
51+
stats.totalSize += int64(entry.Size)
5352

54-
mode := os.FileMode(entry.Mode)
55-
if mode.IsRegular() {
56-
stats.files += len(entry.Path) // count hardlinks!
57-
} else if mode.IsDir() {
58-
stats.directories++
59-
} else if mode&os.ModeSymlink != 0 {
60-
stats.symlinks++
61-
}
53+
mode := os.FileMode(entry.Mode)
54+
if mode.IsRegular() {
55+
stats.files += len(entry.Path) // count hardlinks!
56+
} else if mode.IsDir() {
57+
stats.directories++
58+
} else if mode&os.ModeSymlink != 0 {
59+
stats.symlinks++
6260
}
61+
}
6362

64-
w := newTabwriter(os.Stdout)
65-
defer w.Flush()
63+
w := newTabwriter(os.Stdout)
64+
defer w.Flush()
6665

67-
fmt.Fprintf(w, "resources\t%v\n", stats.resources)
68-
fmt.Fprintf(w, "directories\t%v\n", stats.directories)
69-
fmt.Fprintf(w, "files\t%v\n", stats.files)
70-
fmt.Fprintf(w, "symlinks\t%v\n", stats.symlinks)
71-
fmt.Fprintf(w, "size\t%v\n", humanize.Bytes(uint64(stats.totalSize)))
72-
},
73-
}
74-
)
66+
fmt.Fprintf(w, "resources\t%v\n", stats.resources)
67+
fmt.Fprintf(w, "directories\t%v\n", stats.directories)
68+
fmt.Fprintf(w, "files\t%v\n", stats.files)
69+
fmt.Fprintf(w, "symlinks\t%v\n", stats.symlinks)
70+
fmt.Fprintf(w, "size\t%v\n", humanize.Bytes(uint64(stats.totalSize)))
71+
},
72+
}

cmd/continuity/continuityfs/fuse.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenR
9999
return &fileHandler{
100100
reader: r,
101101
}, nil
102-
103102
}
104103

105104
func (f *File) getDirent(name string) (fuse.Dirent, error) {
@@ -171,7 +170,7 @@ type Dir struct {
171170
// Attr sets the fuse attributes for the directory
172171
func (d *Dir) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
173172
if d.resource == nil {
174-
attr.Mode = os.ModeDir | 0555
173+
attr.Mode = os.ModeDir | 0o555
175174
} else {
176175
attr.Mode = d.resource.Mode()
177176
}
@@ -239,9 +238,7 @@ func NewDir(inode uint64, provider FileContentProvider) *Dir {
239238
}
240239
}
241240

242-
var (
243-
rootPath = fmt.Sprintf("%c", filepath.Separator)
244-
)
241+
var rootPath = fmt.Sprintf("%c", filepath.Separator)
245242

246243
func addNode(path string, node fs.Node, cache map[string]*Dir, provider FileContentProvider) {
247244
dirPath, file := filepath.Split(path)
@@ -310,7 +307,6 @@ func NewFSFromManifest(manifest *continuity.Manifest, mountRoot string, provider
310307
return nil, err
311308
}
312309
if rf, ok := resource.(continuity.RegularFile); ok {
313-
314310
for _, p := range rf.Paths() {
315311
addNode(p, f, dirCache, provider)
316312
}

context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func (c *context) Apply(resource Resource) error {
411411
return fmt.Errorf("resource %v escapes root", resource)
412412
}
413413

414-
var chmod = true
414+
chmod := true
415415
fi, err := c.driver.Lstat(fp)
416416
if err != nil {
417417
if !os.IsNotExist(err) {

fs/copy_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ import (
3232

3333
func TestCopyDirectory(t *testing.T) {
3434
apply := fstest.Apply(
35-
fstest.CreateDir("/etc/", 0755),
36-
fstest.CreateFile("/etc/hosts", []byte("localhost 127.0.0.1"), 0644),
35+
fstest.CreateDir("/etc/", 0o755),
36+
fstest.CreateFile("/etc/hosts", []byte("localhost 127.0.0.1"), 0o644),
3737
fstest.Link("/etc/hosts", "/etc/hosts.allow"),
38-
fstest.CreateDir("/usr/local/lib", 0755),
39-
fstest.CreateFile("/usr/local/lib/libnothing.so", []byte{0x00, 0x00}, 0755),
38+
fstest.CreateDir("/usr/local/lib", 0o755),
39+
fstest.CreateFile("/usr/local/lib/libnothing.so", []byte{0x00, 0x00}, 0o755),
4040
fstest.Symlink("libnothing.so", "/usr/local/lib/libnothing.so.2"),
41-
fstest.CreateDir("/home", 0755),
41+
fstest.CreateDir("/home", 0o755),
4242
)
4343

4444
if err := testCopy(t, apply); err != nil {
@@ -51,7 +51,7 @@ func TestCopyDirectory(t *testing.T) {
5151
// fail.
5252
func TestCopyDirectoryWithLocalSymlink(t *testing.T) {
5353
apply := fstest.Apply(
54-
fstest.CreateFile("nothing.txt", []byte{0x00, 0x00}, 0755),
54+
fstest.CreateFile("nothing.txt", []byte{0x00, 0x00}, 0o755),
5555
fstest.Symlink("nothing.txt", "link-no-nothing.txt"),
5656
)
5757

@@ -66,8 +66,8 @@ func TestCopyWithLargeFile(t *testing.T) {
6666
t.SkipNow()
6767
}
6868
apply := fstest.Apply(
69-
fstest.CreateDir("/banana", 0755),
70-
fstest.CreateRandomFile("/banana/split", time.Now().UnixNano(), 3*1024*1024*1024, 0644),
69+
fstest.CreateDir("/banana", 0o755),
70+
fstest.CreateRandomFile("/banana/split", time.Now().UnixNano(), 3*1024*1024*1024, 0o644),
7171
)
7272

7373
if err := testCopy(t, apply); err != nil {

fs/copy_unix_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ func TestCopyIrregular(t *testing.T) {
8080
var prepared int
8181
prepareSrc := func(src string) {
8282
f0Pipe := filepath.Join(src, "f0.pipe")
83-
if err := unix.Mkfifo(f0Pipe, 0600); err != nil {
83+
if err := unix.Mkfifo(f0Pipe, 0o600); err != nil {
8484
t.Fatal(err)
8585
}
8686
prepared++
8787
f1Normal := filepath.Join(src, "f1.normal")
88-
if err := os.WriteFile(f1Normal, []byte("content of f1.normal"), 0600); err != nil {
88+
if err := os.WriteFile(f1Normal, []byte("content of f1.normal"), 0o600); err != nil {
8989
t.Fatal(err)
9090
}
9191
prepared++
9292
f2Socket := filepath.Join(src, "f2.sock")
93-
if err := unix.Mknod(f2Socket, 0600|unix.S_IFSOCK, 0); err != nil {
93+
if err := unix.Mknod(f2Socket, 0o600|unix.S_IFSOCK, 0); err != nil {
9494
t.Fatal(err)
9595
}
9696
prepared++
9797
f3Dev := filepath.Join(src, "f3.dev")
98-
if err := unix.Mknod(f3Dev, 0600|unix.S_IFCHR, 42); err != nil {
98+
if err := unix.Mknod(f3Dev, 0o600|unix.S_IFCHR, 42); err != nil {
9999
t.Logf("skipping testing S_IFCHR: %v", err)
100100
} else {
101101
prepared++

fs/copy_windows.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func copyFileInfo(fi os.FileInfo, src, name string) error {
4949
secInfo, err := windows.GetNamedSecurityInfo(
5050
src, windows.SE_FILE_OBJECT,
5151
windows.OWNER_SECURITY_INFORMATION|windows.DACL_SECURITY_INFORMATION)
52-
5352
if err != nil {
5453
return err
5554
}
@@ -68,7 +67,6 @@ func copyFileInfo(fi os.FileInfo, src, name string) error {
6867
name, windows.SE_FILE_OBJECT,
6968
windows.OWNER_SECURITY_INFORMATION|windows.DACL_SECURITY_INFORMATION,
7069
sid, nil, dacl, nil); err != nil {
71-
7270
return err
7371
}
7472
return nil

fs/diff.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ type ChangeFunc func(ChangeKind, string, os.FileInfo, error) error
8080
//
8181
// The change callback is called by the order of path names and
8282
// should be appliable in that order.
83-
// Due to this apply ordering, the following is true
84-
// - Removed directory trees only create a single change for the root
85-
// directory removed. Remaining changes are implied.
86-
// - A directory which is modified to become a file will not have
87-
// delete entries for sub-path items, their removal is implied
88-
// by the removal of the parent directory.
83+
//
84+
// Due to this apply ordering, the following is true
85+
// - Removed directory trees only create a single change for the root
86+
// directory removed. Remaining changes are implied.
87+
// - A directory which is modified to become a file will not have
88+
// delete entries for sub-path items, their removal is implied
89+
// by the removal of the parent directory.
8990
//
9091
// Opaque directories will not be treated specially and each file
9192
// removed from the base directory will show up as a removal.

0 commit comments

Comments
 (0)