From 0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 21 Jul 2015 19:49:42 +0200 Subject: [PATCH] pkg: mount: golint Fix the following warnings: pkg/mount/mountinfo.go:5:6: type name will be used as mount.MountInfo by other packages, and that stutters; consider calling this Info pkg/mount/mountinfo.go:7:2: struct field Id should be ID Signed-off-by: Antonio Murdaca --- hack/make/validate-lint | 1 + pkg/mount/mount.go | 2 +- pkg/mount/mountinfo.go | 8 ++++---- pkg/mount/mountinfo_freebsd.go | 6 +++--- pkg/mount/mountinfo_linux.go | 12 ++++++------ pkg/mount/mountinfo_linux_test.go | 4 ++-- pkg/mount/mountinfo_unsupported.go | 2 +- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/hack/make/validate-lint b/hack/make/validate-lint index 34020ba6cb..121b65d504 100644 --- a/hack/make/validate-lint +++ b/hack/make/validate-lint @@ -21,6 +21,7 @@ packages=( pkg/homedir pkg/listenbuffer pkg/mflag/example + pkg/mount pkg/namesgenerator pkg/promise pkg/pubsub diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 9a20df219f..ed7216e5c0 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -5,7 +5,7 @@ import ( ) // GetMounts retrieves a list of mounts for the current running process. -func GetMounts() ([]*MountInfo, error) { +func GetMounts() ([]*Info, error) { return parseMountTable() } diff --git a/pkg/mount/mountinfo.go b/pkg/mount/mountinfo.go index 8ea08648c0..e3fc3535e9 100644 --- a/pkg/mount/mountinfo.go +++ b/pkg/mount/mountinfo.go @@ -1,10 +1,10 @@ package mount -// MountInfo reveals information about a particular mounted filesystem. This +// Info reveals information about a particular mounted filesystem. This // struct is populated from the content in the /proc//mountinfo file. -type MountInfo struct { - // Id is a unique identifier of the mount (may be reused after umount). - Id int +type Info struct { + // ID is a unique identifier of the mount (may be reused after umount). + ID int // Parent indicates the ID of the mount parent (or of self for the top of the // mount tree). diff --git a/pkg/mount/mountinfo_freebsd.go b/pkg/mount/mountinfo_freebsd.go index add7c3b0ed..4f32edcd90 100644 --- a/pkg/mount/mountinfo_freebsd.go +++ b/pkg/mount/mountinfo_freebsd.go @@ -15,7 +15,7 @@ import ( // Parse /proc/self/mountinfo because comparing Dev and ino does not work from // bind mounts. -func parseMountTable() ([]*MountInfo, error) { +func parseMountTable() ([]*Info, error) { var rawEntries *C.struct_statfs count := int(C.getmntinfo(&rawEntries, C.MNT_WAIT)) @@ -29,9 +29,9 @@ func parseMountTable() ([]*MountInfo, error) { header.Len = count header.Data = uintptr(unsafe.Pointer(rawEntries)) - var out []*MountInfo + var out []*Info for _, entry := range entries { - var mountinfo MountInfo + var mountinfo Info mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0]) mountinfo.Source = C.GoString(&entry.f_mntfromname[0]) mountinfo.Fstype = C.GoString(&entry.f_fstypename[0]) diff --git a/pkg/mount/mountinfo_linux.go b/pkg/mount/mountinfo_linux.go index 351a58ea00..be69fee1d7 100644 --- a/pkg/mount/mountinfo_linux.go +++ b/pkg/mount/mountinfo_linux.go @@ -30,7 +30,7 @@ const ( // Parse /proc/self/mountinfo because comparing Dev and ino does not work from // bind mounts -func parseMountTable() ([]*MountInfo, error) { +func parseMountTable() ([]*Info, error) { f, err := os.Open("/proc/self/mountinfo") if err != nil { return nil, err @@ -40,10 +40,10 @@ func parseMountTable() ([]*MountInfo, error) { return parseInfoFile(f) } -func parseInfoFile(r io.Reader) ([]*MountInfo, error) { +func parseInfoFile(r io.Reader) ([]*Info, error) { var ( s = bufio.NewScanner(r) - out = []*MountInfo{} + out = []*Info{} ) for s.Scan() { @@ -52,13 +52,13 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) { } var ( - p = &MountInfo{} + p = &Info{} text = s.Text() optionalFields string ) if _, err := fmt.Sscanf(text, mountinfoFormat, - &p.Id, &p.Parent, &p.Major, &p.Minor, + &p.ID, &p.Parent, &p.Major, &p.Minor, &p.Root, &p.Mountpoint, &p.Opts, &optionalFields); err != nil { return nil, fmt.Errorf("Scanning '%s' failed: %s", text, err) } @@ -84,7 +84,7 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) { // PidMountInfo collects the mounts for a specific process ID. If the process // ID is unknown, it is better to use `GetMounts` which will inspect // "/proc/self/mountinfo" instead. -func PidMountInfo(pid int) ([]*MountInfo, error) { +func PidMountInfo(pid int) ([]*Info, error) { f, err := os.Open(fmt.Sprintf("/proc/%d/mountinfo", pid)) if err != nil { return nil, err diff --git a/pkg/mount/mountinfo_linux_test.go b/pkg/mount/mountinfo_linux_test.go index e92b7e2c74..812d12e826 100644 --- a/pkg/mount/mountinfo_linux_test.go +++ b/pkg/mount/mountinfo_linux_test.go @@ -457,8 +457,8 @@ func TestParseFedoraMountinfoFields(t *testing.T) { if len(infos) != expectedLength { t.Fatalf("Expected %d entries, got %d", expectedLength, len(infos)) } - mi := MountInfo{ - Id: 15, + mi := Info{ + ID: 15, Parent: 35, Major: 0, Minor: 3, diff --git a/pkg/mount/mountinfo_unsupported.go b/pkg/mount/mountinfo_unsupported.go index 352336b9a3..8245f01d42 100644 --- a/pkg/mount/mountinfo_unsupported.go +++ b/pkg/mount/mountinfo_unsupported.go @@ -7,6 +7,6 @@ import ( "runtime" ) -func parseMountTable() ([]*MountInfo, error) { +func parseMountTable() ([]*Info, error) { return nil, fmt.Errorf("mount.parseMountTable is not implemented on %s/%s", runtime.GOOS, runtime.GOARCH) }