From 159e27492185cfc6f65501d239d95014094fc73c Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:40:07 +0200 Subject: [PATCH] build: fix linting issues reported by golangci-lint on windows --- backend/local/remove_windows.go | 8 ++---- backend/netstorage/netstorage.go | 4 +-- cmd/serve/nfs/nfs_unsupported.go | 4 +-- fs/accounting/token_bucket.go | 2 +- fs/fserrors/retriable_errors_windows.go | 4 +-- lib/buildinfo/osversion_windows.go | 35 ------------------------- lib/file/mkdir_windows_test.go | 6 ++++- lib/file/preallocate_windows.go | 16 +++++------ lib/terminal/hidden_windows.go | 2 +- 9 files changed, 21 insertions(+), 60 deletions(-) diff --git a/backend/local/remove_windows.go b/backend/local/remove_windows.go index a04f4af66..70d65b63e 100644 --- a/backend/local/remove_windows.go +++ b/backend/local/remove_windows.go @@ -4,14 +4,10 @@ package local import ( "os" - "syscall" "time" "github.com/rclone/rclone/fs" -) - -const ( - ERROR_SHARING_VIOLATION syscall.Errno = 32 + "golang.org/x/sys/windows" ) // Removes name, retrying on a sharing violation @@ -27,7 +23,7 @@ func remove(name string) (err error) { if !ok { break } - if pathErr.Err != ERROR_SHARING_VIOLATION { + if pathErr.Err != windows.ERROR_SHARING_VIOLATION { break } fs.Logf(name, "Remove detected sharing violation - retry %d/%d sleeping %v", i+1, maxTries, sleepTime) diff --git a/backend/netstorage/netstorage.go b/backend/netstorage/netstorage.go index d365918ca..108c03596 100755 --- a/backend/netstorage/netstorage.go +++ b/backend/netstorage/netstorage.go @@ -443,7 +443,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e } URL := f.url(dir) - files, err := f.netStorageDirRequest(ctx, dir, URL) + files, err := f.netStorageDirRequest(ctx, URL) if err != nil { return nil, err } @@ -932,7 +932,7 @@ func (f *Fs) netStorageStatRequest(ctx context.Context, URL string, directory bo } // netStorageDirRequest performs a NetStorage dir request -func (f *Fs) netStorageDirRequest(ctx context.Context, dir string, URL string) ([]File, error) { +func (f *Fs) netStorageDirRequest(ctx context.Context, URL string) ([]File, error) { const actionHeader = "version=1&action=dir&format=xml&encoding=utf-8" statResp := &Stat{} if _, err := f.callBackend(ctx, URL, "GET", actionHeader, false, statResp, nil); err != nil { diff --git a/cmd/serve/nfs/nfs_unsupported.go b/cmd/serve/nfs/nfs_unsupported.go index a438c9748..c9b9f5bbf 100644 --- a/cmd/serve/nfs/nfs_unsupported.go +++ b/cmd/serve/nfs/nfs_unsupported.go @@ -8,5 +8,5 @@ import ( "github.com/spf13/cobra" ) -// For unsupported platforms we just put nil -var Command *cobra.Command = nil +// Command is just nil for unsupported platforms +var Command *cobra.Command diff --git a/fs/accounting/token_bucket.go b/fs/accounting/token_bucket.go index 29204b5eb..5e5b597e1 100644 --- a/fs/accounting/token_bucket.go +++ b/fs/accounting/token_bucket.go @@ -40,7 +40,7 @@ type tokenBucket struct { // Return true if limit is disabled // // Call with lock held -func (bs *buckets) _isOff() bool { +func (bs *buckets) _isOff() bool { //nolint:unused // Don't include unused when running golangci-lint in case its on windows where this is not called return bs[0] == nil } diff --git a/fs/fserrors/retriable_errors_windows.go b/fs/fserrors/retriable_errors_windows.go index 58751c50f..17a62af5c 100644 --- a/fs/fserrors/retriable_errors_windows.go +++ b/fs/fserrors/retriable_errors_windows.go @@ -23,8 +23,8 @@ const ( WSAEHOSTUNREACH syscall.Errno = 10065 WSAEDISCON syscall.Errno = 10101 WSAEREFUSED syscall.Errno = 10112 - WSAHOST_NOT_FOUND syscall.Errno = 11001 - WSATRY_AGAIN syscall.Errno = 11002 + WSAHOST_NOT_FOUND syscall.Errno = 11001 //nolint:revive // Don't include revive when running golangci-lint to avoid var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive) + WSATRY_AGAIN syscall.Errno = 11002 //nolint:revive // Don't include revive when running golangci-lint to avoid var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive) ) func init() { diff --git a/lib/buildinfo/osversion_windows.go b/lib/buildinfo/osversion_windows.go index bcc903c36..0626d4227 100644 --- a/lib/buildinfo/osversion_windows.go +++ b/lib/buildinfo/osversion_windows.go @@ -7,7 +7,6 @@ import ( "github.com/shirou/gopsutil/v3/host" "golang.org/x/sys/windows" - "golang.org/x/sys/windows/registry" ) // GetOSVersion returns OS version, kernel and bitness @@ -96,37 +95,3 @@ func getRegistryVersionString(name string) string { return windows.UTF16ToString(regBuf[:]) } - -func getRegistryVersionInt(name string) int { - var ( - err error - handle windows.Handle - bufLen uint32 - valType uint32 - ) - - err = windows.RegOpenKeyEx(windows.HKEY_LOCAL_MACHINE, regVersionKeyUTF16, 0, windows.KEY_READ|windows.KEY_WOW64_64KEY, &handle) - if err != nil { - return 0 - } - defer func() { - _ = windows.RegCloseKey(handle) - }() - - nameUTF16 := windows.StringToUTF16Ptr(name) - err = windows.RegQueryValueEx(handle, nameUTF16, nil, &valType, nil, &bufLen) - if err != nil { - return 0 - } - - if valType != registry.DWORD || bufLen != 4 { - return 0 - } - var val32 uint32 - err = windows.RegQueryValueEx(handle, nameUTF16, nil, &valType, (*byte)(unsafe.Pointer(&val32)), &bufLen) - if err != nil { - return 0 - } - - return int(val32) -} diff --git a/lib/file/mkdir_windows_test.go b/lib/file/mkdir_windows_test.go index 5e6fdc60e..75e050bf7 100644 --- a/lib/file/mkdir_windows_test.go +++ b/lib/file/mkdir_windows_test.go @@ -34,7 +34,11 @@ func TestMkdirAll(t *testing.T) { if err != nil { t.Fatalf("create %q: %s", fpath, err) } - defer f.Close() + defer func() { + if err := f.Close(); err != nil { + t.Fatalf("Close %q: %s", fpath, err) + } + }() // Can't make directory named after file. err = MkdirAll(fpath, 0777) diff --git a/lib/file/preallocate_windows.go b/lib/file/preallocate_windows.go index e1d0c1a01..928276c1b 100644 --- a/lib/file/preallocate_windows.go +++ b/lib/file/preallocate_windows.go @@ -55,10 +55,10 @@ func PreAllocate(size int64, out *os.File) error { // Query info about the block sizes on the file system _, _, e1 := ntQueryVolumeInformationFile.Call( - uintptr(out.Fd()), + out.Fd(), uintptr(unsafe.Pointer(&iosb)), uintptr(unsafe.Pointer(&fsSizeInfo)), - uintptr(unsafe.Sizeof(fsSizeInfo)), + unsafe.Sizeof(fsSizeInfo), uintptr(3), // FileFsSizeInformation ) if e1 != nil && e1 != syscall.Errno(0) { @@ -74,14 +74,14 @@ func PreAllocate(size int64, out *os.File) error { // Ask for the allocation _, _, e1 = ntSetInformationFile.Call( - uintptr(out.Fd()), + out.Fd(), uintptr(unsafe.Pointer(&iosb)), uintptr(unsafe.Pointer(&allocInfo)), - uintptr(unsafe.Sizeof(allocInfo)), + unsafe.Sizeof(allocInfo), uintptr(19), // FileAllocationInformation ) if e1 != nil && e1 != syscall.Errno(0) { - if e1 == syscall.Errno(windows.ERROR_DISK_FULL) || e1 == syscall.Errno(windows.ERROR_HANDLE_DISK_FULL) { + if e1 == windows.ERROR_DISK_FULL || e1 == windows.ERROR_HANDLE_DISK_FULL { return ErrDiskFull } return fmt.Errorf("preAllocate NtSetInformationFile failed: %w", e1) @@ -90,10 +90,6 @@ func PreAllocate(size int64, out *os.File) error { return nil } -const ( - FSCTL_SET_SPARSE = 0x000900c4 // Control code to set or clears the FILE_ATTRIBUTE_SPARSE_FILE attribute of a file. -) - // SetSparseImplemented is a constant indicating whether the // implementation of SetSparse actually does anything. const SetSparseImplemented = true @@ -101,7 +97,7 @@ const SetSparseImplemented = true // SetSparse makes the file be a sparse file func SetSparse(out *os.File) error { var bytesReturned uint32 - err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, &bytesReturned, nil) + err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), windows.FSCTL_SET_SPARSE, nil, 0, nil, 0, &bytesReturned, nil) if err != nil { return fmt.Errorf("DeviceIoControl FSCTL_SET_SPARSE: %w", err) } diff --git a/lib/terminal/hidden_windows.go b/lib/terminal/hidden_windows.go index cd0a980b0..62eda1e3d 100644 --- a/lib/terminal/hidden_windows.go +++ b/lib/terminal/hidden_windows.go @@ -13,7 +13,7 @@ func HideConsole() { if getConsoleWindow.Find() == nil && showWindow.Find() == nil { hwnd, _, _ := getConsoleWindow.Call() if hwnd != 0 { - showWindow.Call(hwnd, 0) + _, _, _ = showWindow.Call(hwnd, 0) } } }