mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +08:00
build: fix linting issues reported by golangci-lint on windows
This commit is contained in:
parent
fdc56b21c1
commit
159e274921
|
@ -4,14 +4,10 @@ package local
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
)
|
"golang.org/x/sys/windows"
|
||||||
|
|
||||||
const (
|
|
||||||
ERROR_SHARING_VIOLATION syscall.Errno = 32
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Removes name, retrying on a sharing violation
|
// Removes name, retrying on a sharing violation
|
||||||
|
@ -27,7 +23,7 @@ func remove(name string) (err error) {
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if pathErr.Err != ERROR_SHARING_VIOLATION {
|
if pathErr.Err != windows.ERROR_SHARING_VIOLATION {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fs.Logf(name, "Remove detected sharing violation - retry %d/%d sleeping %v", i+1, maxTries, sleepTime)
|
fs.Logf(name, "Remove detected sharing violation - retry %d/%d sleeping %v", i+1, maxTries, sleepTime)
|
||||||
|
|
|
@ -443,7 +443,7 @@ func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err e
|
||||||
}
|
}
|
||||||
|
|
||||||
URL := f.url(dir)
|
URL := f.url(dir)
|
||||||
files, err := f.netStorageDirRequest(ctx, dir, URL)
|
files, err := f.netStorageDirRequest(ctx, URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -932,7 +932,7 @@ func (f *Fs) netStorageStatRequest(ctx context.Context, URL string, directory bo
|
||||||
}
|
}
|
||||||
|
|
||||||
// netStorageDirRequest performs a NetStorage dir request
|
// 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"
|
const actionHeader = "version=1&action=dir&format=xml&encoding=utf-8"
|
||||||
statResp := &Stat{}
|
statResp := &Stat{}
|
||||||
if _, err := f.callBackend(ctx, URL, "GET", actionHeader, false, statResp, nil); err != nil {
|
if _, err := f.callBackend(ctx, URL, "GET", actionHeader, false, statResp, nil); err != nil {
|
||||||
|
|
|
@ -8,5 +8,5 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// For unsupported platforms we just put nil
|
// Command is just nil for unsupported platforms
|
||||||
var Command *cobra.Command = nil
|
var Command *cobra.Command
|
||||||
|
|
|
@ -40,7 +40,7 @@ type tokenBucket struct {
|
||||||
// Return true if limit is disabled
|
// Return true if limit is disabled
|
||||||
//
|
//
|
||||||
// Call with lock held
|
// 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
|
return bs[0] == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ const (
|
||||||
WSAEHOSTUNREACH syscall.Errno = 10065
|
WSAEHOSTUNREACH syscall.Errno = 10065
|
||||||
WSAEDISCON syscall.Errno = 10101
|
WSAEDISCON syscall.Errno = 10101
|
||||||
WSAEREFUSED syscall.Errno = 10112
|
WSAEREFUSED syscall.Errno = 10112
|
||||||
WSAHOST_NOT_FOUND syscall.Errno = 11001
|
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
|
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() {
|
func init() {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/host"
|
"github.com/shirou/gopsutil/v3/host"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"golang.org/x/sys/windows/registry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetOSVersion returns OS version, kernel and bitness
|
// GetOSVersion returns OS version, kernel and bitness
|
||||||
|
@ -96,37 +95,3 @@ func getRegistryVersionString(name string) string {
|
||||||
|
|
||||||
return windows.UTF16ToString(regBuf[:])
|
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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,7 +34,11 @@ func TestMkdirAll(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("create %q: %s", fpath, err)
|
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.
|
// Can't make directory named after file.
|
||||||
err = MkdirAll(fpath, 0777)
|
err = MkdirAll(fpath, 0777)
|
||||||
|
|
|
@ -55,10 +55,10 @@ func PreAllocate(size int64, out *os.File) error {
|
||||||
|
|
||||||
// Query info about the block sizes on the file system
|
// Query info about the block sizes on the file system
|
||||||
_, _, e1 := ntQueryVolumeInformationFile.Call(
|
_, _, e1 := ntQueryVolumeInformationFile.Call(
|
||||||
uintptr(out.Fd()),
|
out.Fd(),
|
||||||
uintptr(unsafe.Pointer(&iosb)),
|
uintptr(unsafe.Pointer(&iosb)),
|
||||||
uintptr(unsafe.Pointer(&fsSizeInfo)),
|
uintptr(unsafe.Pointer(&fsSizeInfo)),
|
||||||
uintptr(unsafe.Sizeof(fsSizeInfo)),
|
unsafe.Sizeof(fsSizeInfo),
|
||||||
uintptr(3), // FileFsSizeInformation
|
uintptr(3), // FileFsSizeInformation
|
||||||
)
|
)
|
||||||
if e1 != nil && e1 != syscall.Errno(0) {
|
if e1 != nil && e1 != syscall.Errno(0) {
|
||||||
|
@ -74,14 +74,14 @@ func PreAllocate(size int64, out *os.File) error {
|
||||||
|
|
||||||
// Ask for the allocation
|
// Ask for the allocation
|
||||||
_, _, e1 = ntSetInformationFile.Call(
|
_, _, e1 = ntSetInformationFile.Call(
|
||||||
uintptr(out.Fd()),
|
out.Fd(),
|
||||||
uintptr(unsafe.Pointer(&iosb)),
|
uintptr(unsafe.Pointer(&iosb)),
|
||||||
uintptr(unsafe.Pointer(&allocInfo)),
|
uintptr(unsafe.Pointer(&allocInfo)),
|
||||||
uintptr(unsafe.Sizeof(allocInfo)),
|
unsafe.Sizeof(allocInfo),
|
||||||
uintptr(19), // FileAllocationInformation
|
uintptr(19), // FileAllocationInformation
|
||||||
)
|
)
|
||||||
if e1 != nil && e1 != syscall.Errno(0) {
|
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 ErrDiskFull
|
||||||
}
|
}
|
||||||
return fmt.Errorf("preAllocate NtSetInformationFile failed: %w", e1)
|
return fmt.Errorf("preAllocate NtSetInformationFile failed: %w", e1)
|
||||||
|
@ -90,10 +90,6 @@ func PreAllocate(size int64, out *os.File) error {
|
||||||
return nil
|
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
|
// SetSparseImplemented is a constant indicating whether the
|
||||||
// implementation of SetSparse actually does anything.
|
// implementation of SetSparse actually does anything.
|
||||||
const SetSparseImplemented = true
|
const SetSparseImplemented = true
|
||||||
|
@ -101,7 +97,7 @@ const SetSparseImplemented = true
|
||||||
// SetSparse makes the file be a sparse file
|
// SetSparse makes the file be a sparse file
|
||||||
func SetSparse(out *os.File) error {
|
func SetSparse(out *os.File) error {
|
||||||
var bytesReturned uint32
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("DeviceIoControl FSCTL_SET_SPARSE: %w", err)
|
return fmt.Errorf("DeviceIoControl FSCTL_SET_SPARSE: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func HideConsole() {
|
||||||
if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
|
if getConsoleWindow.Find() == nil && showWindow.Find() == nil {
|
||||||
hwnd, _, _ := getConsoleWindow.Call()
|
hwnd, _, _ := getConsoleWindow.Call()
|
||||||
if hwnd != 0 {
|
if hwnd != 0 {
|
||||||
showWindow.Call(hwnd, 0)
|
_, _, _ = showWindow.Call(hwnd, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user