Skip to content

Commit

Permalink
Merge pull request #26 from dell/ci-add-golangci-lint
Browse files Browse the repository at this point in the history
ci(linters): added golangci-lint
  • Loading branch information
shaynafinocchiaro authored Aug 7, 2023
2 parents cae4810 + 392f8a6 commit b9a2646
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 62 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: linters

on:
push:
branches: [main]
pull_request:
branches: ["**"]

permissions:
contents: read

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: false
- name: Checkout the code
uses: actions/[email protected]
- name: Vendor packages
run: |
go mod vendor
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53
skip-cache: true
30 changes: 30 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
run:
timeout: 20m
issue-exit-code: 0 # we will change this later
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly

issues:
max-issues-per-linter: 0
max-same-issues: 0
new: false

output:
print-linter-name: true
sort-results: true
uniq-by-line: false
print-issued-lines: true

linters:
disable-all: true
fast: false
enable:
# A stricter replacement for gofmt.
- gofumpt
# Inspects source code for security problems.
- gosec
# Check for correctness of programs.
- govet
# Drop-in replacement of golint.
- revive
26 changes: 13 additions & 13 deletions gofsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,36 +157,36 @@ func Unmount(ctx context.Context, target string) error {
return fs.Unmount(ctx, target)
}

//GetMountInfoFromDevice retrieves mount information associated with the volume
// GetMountInfoFromDevice retrieves mount information associated with the volume
func GetMountInfoFromDevice(ctx context.Context, devID string) (*DeviceMountInfo, error) {
return fs.GetMountInfoFromDevice(ctx, devID)
}

//GetMpathNameFromDevice retrieves mpath device name from device name
// GetMpathNameFromDevice retrieves mpath device name from device name
func GetMpathNameFromDevice(ctx context.Context, device string) (string, error) {
return fs.getMpathNameFromDevice(ctx, device)
}

//ResizeFS expands the filesystem to the new size of underlying device
// ResizeFS expands the filesystem to the new size of underlying device
func ResizeFS(
ctx context.Context,
volumePath, devicePath, ppathDevice,
mpathDevice, fsType string) error {
return fs.resizeFS(ctx, volumePath, devicePath, ppathDevice, mpathDevice, fsType)
}

//ResizeMultipath expands the multipath volumes
// ResizeMultipath expands the multipath volumes
func ResizeMultipath(ctx context.Context, deviceName string) error {
return fs.resizeMultipath(ctx, deviceName)
}

//FindFSType fetches the filesystem type on mountpoint
// FindFSType fetches the filesystem type on mountpoint
func FindFSType(
ctx context.Context, mountpoint string) (fsType string, err error) {
return fs.findFSType(ctx, mountpoint)
}

//DeviceRescan rescan the device for size alterations
// DeviceRescan rescan the device for size alterations
func DeviceRescan(ctx context.Context,
devicePath string) error {
return fs.deviceRescan(ctx, devicePath)
Expand All @@ -196,15 +196,15 @@ func DeviceRescan(ctx context.Context,
//
// * Linux hosts use mount_namespaces to obtain mount information.
//
// Support for mount_namespaces was introduced to the Linux kernel
// in 2.2.26 (http://man7.org/linux/man-pages/man5/proc.5.html) on
// 2004/02/04.
// Support for mount_namespaces was introduced to the Linux kernel
// in 2.2.26 (http://man7.org/linux/man-pages/man5/proc.5.html) on
// 2004/02/04.
//
// The kernel documents the contents of "/proc/<pid>/mountinfo" at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
// The kernel documents the contents of "/proc/<pid>/mountinfo" at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
//
// * Darwin hosts parse the output of the "mount" command to obtain
// mount information.
// - Darwin hosts parse the output of the "mount" command to obtain
// mount information.
func GetMounts(ctx context.Context) ([]Info, error) {
return fs.GetMounts(ctx)
}
Expand Down
26 changes: 13 additions & 13 deletions gofsutil_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,36 @@ func (fs *FS) Unmount(ctx context.Context, target string) error {
return fs.unmount(ctx, target)
}

//GetMountInfoFromDevice retrieves mount information associated with the volume
// GetMountInfoFromDevice retrieves mount information associated with the volume
func (fs *FS) GetMountInfoFromDevice(ctx context.Context, devID string) (*DeviceMountInfo, error) {
return fs.getMountInfoFromDevice(ctx, devID)
}

//GetMpathNameFromDevice retrieves mpath device name from device name
// GetMpathNameFromDevice retrieves mpath device name from device name
func (fs *FS) GetMpathNameFromDevice(ctx context.Context, device string) (string, error) {
return fs.getMpathNameFromDevice(ctx, device)
}

//ResizeFS expands the filesystem to the new size of underlying device
// ResizeFS expands the filesystem to the new size of underlying device
func (fs *FS) ResizeFS(
ctx context.Context,
volumePath, devicePath, ppathDevice,
mpathDevice, fsType string) error {
return fs.resizeFS(ctx, volumePath, devicePath, ppathDevice, mpathDevice, fsType)
}

//FindFSType fetches the filesystem type on mountpoint
// FindFSType fetches the filesystem type on mountpoint
func (fs *FS) FindFSType(
ctx context.Context, mountpoint string) (fsType string, err error) {
return fs.findFSType(ctx, mountpoint)
}

//ResizeMultipath resizes the multipath devices mounted on FS
// ResizeMultipath resizes the multipath devices mounted on FS
func (fs *FS) ResizeMultipath(ctx context.Context, deviceName string) error {
return fs.resizeMultipath(ctx, deviceName)
}

//DeviceRescan rescan the device for size alterations
// DeviceRescan rescan the device for size alterations
func (fs *FS) DeviceRescan(ctx context.Context,
devicePath string) error {
return fs.deviceRescan(ctx, devicePath)
Expand All @@ -125,15 +125,15 @@ func (fs *FS) DeviceRescan(ctx context.Context,
//
// * Linux hosts use mount_namespaces to obtain mount information.
//
// Support for mount_namespaces was introduced to the Linux kernel
// in 2.2.26 (http://man7.org/linux/man-pages/man5/proc.5.html) on
// 2004/02/04.
// Support for mount_namespaces was introduced to the Linux kernel
// in 2.2.26 (http://man7.org/linux/man-pages/man5/proc.5.html) on
// 2004/02/04.
//
// The kernel documents the contents of "/proc/<pid>/mountinfo" at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
// The kernel documents the contents of "/proc/<pid>/mountinfo" at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
//
// * Darwin hosts parse the output of the "mount" command to obtain
// mount information.
// - Darwin hosts parse the output of the "mount" command to obtain
// mount information.
func (fs *FS) GetMounts(ctx context.Context) ([]Info, error) {
return fs.getMounts(ctx)
}
Expand Down
14 changes: 7 additions & 7 deletions gofsutil_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ func (fs *mockfs) Unmount(ctx context.Context, target string) error {
//
// * Linux hosts use mount_namespaces to obtain mount information.
//
// Support for mount_namespaces was introduced to the Linux kernel
// in 2.2.26 (http://man7.org/linux/man-pages/man5/proc.5.html) on
// 2004/02/04.
// Support for mount_namespaces was introduced to the Linux kernel
// in 2.2.26 (http://man7.org/linux/man-pages/man5/proc.5.html) on
// 2004/02/04.
//
// The kernel documents the contents of "/proc/<pid>/mountinfo" at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
// The kernel documents the contents of "/proc/<pid>/mountinfo" at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt.
//
// * Darwin hosts parse the output of the "mount" command to obtain
// mount information.
// - Darwin hosts parse the output of the "mount" command to obtain
// mount information.
func (fs *mockfs) GetMounts(ctx context.Context) ([]Info, error) {
return fs.getMounts(ctx)
}
Expand Down
28 changes: 14 additions & 14 deletions gofsutil_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type Info struct {
Opts []string
}

//DeviceMountInfo describes the filesystem mount information
//related to the mounted CSI device
// DeviceMountInfo describes the filesystem mount information
// related to the mounted CSI device
type DeviceMountInfo struct {
DeviceNames []string
MPathName string
Expand All @@ -79,17 +79,17 @@ type DeviceMountInfo struct {
// Entry is a superset of Info and maps to the fields of a mount table
// entry:
//
// (1) mount ID: unique identifier of the mount (may be reused after umount)
// (2) parent ID: ID of parent (or of self for the top of the mount tree)
// (3) major:minor: value of st_dev for files on filesystem
// (4) root: root of the mount within the filesystem
// (5) mount point: mount point relative to the process's root
// (6) mount options: per mount options
// (7) optional fields: zero or more fields of the form "tag[:value]"
// (8) separator: marks the end of the optional fields
// (9) filesystem type: name of filesystem of the form "type[.subtype]"
// (10) mount source: filesystem specific information or "none"
// (11) super options: per super block options
// (1) mount ID: unique identifier of the mount (may be reused after umount)
// (2) parent ID: ID of parent (or of self for the top of the mount tree)
// (3) major:minor: value of st_dev for files on filesystem
// (4) root: root of the mount within the filesystem
// (5) mount point: mount point relative to the process's root
// (6) mount options: per mount options
// (7) optional fields: zero or more fields of the form "tag[:value]"
// (8) separator: marks the end of the optional fields
// (9) filesystem type: name of filesystem of the form "type[.subtype]"
// (10) mount source: filesystem specific information or "none"
// (11) super options: per super block options
type Entry struct {
// Root of the mount within the filesystem.
Root string
Expand Down Expand Up @@ -264,7 +264,7 @@ func ReadProcMountsFrom(
//
// The argument list returned is built as follows:
//
// mount [-t $fsType] [-o $options] [$source] $target
// mount [-t $fsType] [-o $options] [$source] $target
func MakeMountArgs(
ctx context.Context,
source, target, fsType string,
Expand Down
6 changes: 3 additions & 3 deletions gofsutil_mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (fs *FS) bindMount(
return fs.doMount(ctx, "mount", source, target, "", opts...)
}

//isLsblkNew returns true if lsblk version is greater than 2.3 and false otherwise
// isLsblkNew returns true if lsblk version is greater than 2.3 and false otherwise
func (fs *FS) isLsblkNew() (bool, error) {
lsblkNew := false
checkVersCmd := "lsblk -V"
Expand Down Expand Up @@ -498,7 +498,7 @@ func (fs *FS) getMountInfoFromDevice(
return mountInfo, nil
}

//FindFSType fetches the filesystem type on mountpoint
// FindFSType fetches the filesystem type on mountpoint
func (fs *FS) findFSType(
ctx context.Context, mountpoint string) (fsType string, err error) {
path := filepath.Clean(mountpoint)
Expand Down Expand Up @@ -616,7 +616,7 @@ func (fs *FS) expandXfs(volumePath string) error {
return nil
}

//DeviceRescan rescan the device for size alterations
// DeviceRescan rescan the device for size alterations
func (fs *FS) deviceRescan(ctx context.Context,
devicePath string) error {
path := filepath.Clean(devicePath)
Expand Down
24 changes: 12 additions & 12 deletions gofsutil_removeduplicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ function. If the situation should ever change such that mount options
number in the thousands then this function should defer to
RemoveDuplicatesLinearOrdered instead of RemoveDuplicatesExponentialOrdered.
$ go test -run Bench -bench BenchmarkRemoveDuplicates -benchmem -v
goos: darwin
goarch: amd64
pkg: github.com/thecodeteam/gofsutil
BenchmarkRemoveDuplicates_Exponential_Ordered___SmallData-8 20000000 121 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Exponential_Unordered_SmallData-8 20000000 99.0 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Linear______Ordered___SmallData-8 2000000 715 ns/op 288 B/op 1 allocs/op
BenchmarkRemoveDuplicates_Exponential_Ordered___BigData-8 20000 84731 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Exponential_Unordered_BigData-8 10000 156660 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Linear______Ordered___BigData-8 50000 36971 ns/op 20512 B/op 2 allocs/op
PASS
ok github.com/thecodeteam/gofsutil 22.085s
$ go test -run Bench -bench BenchmarkRemoveDuplicates -benchmem -v
goos: darwin
goarch: amd64
pkg: github.com/thecodeteam/gofsutil
BenchmarkRemoveDuplicates_Exponential_Ordered___SmallData-8 20000000 121 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Exponential_Unordered_SmallData-8 20000000 99.0 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Linear______Ordered___SmallData-8 2000000 715 ns/op 288 B/op 1 allocs/op
BenchmarkRemoveDuplicates_Exponential_Ordered___BigData-8 20000 84731 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Exponential_Unordered_BigData-8 10000 156660 ns/op 0 B/op 0 allocs/op
BenchmarkRemoveDuplicates_Linear______Ordered___BigData-8 50000 36971 ns/op 20512 B/op 2 allocs/op
PASS
ok github.com/thecodeteam/gofsutil 22.085s
*/
func RemoveDuplicates(a []string) []string {
return RemoveDuplicatesExponentialOrdered(a)
Expand Down

0 comments on commit b9a2646

Please sign in to comment.