diff --git a/cmd/os_windows.go b/cmd/os_windows.go index 98c797c88..758f3856a 100644 --- a/cmd/os_windows.go +++ b/cmd/os_windows.go @@ -80,11 +80,11 @@ func readDirFn(dirPath string, filter func(name string, typ os.FileMode) error) continue } - var typ os.FileMode = 0 // regular file + var typ os.FileMode // regular file switch { case data.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0: // Reparse point is a symlink - fi, err := os.Stat(pathJoin(dirPath, string(name))) + fi, err := os.Stat(pathJoin(dirPath, name)) if err != nil { // It got deleted in the meantime, not found // or returns too many symlinks ignore this @@ -153,7 +153,7 @@ func readDirWithOpts(dirPath string, opts readDirOpts) (entries []string, err er switch { case data.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0: // Reparse point is a symlink - fi, err := os.Stat(pathJoin(dirPath, string(name))) + fi, err := os.Stat(pathJoin(dirPath, name)) if err != nil { // It got deleted in the meantime, not found // or returns too many symlinks ignore this @@ -170,7 +170,7 @@ func readDirWithOpts(dirPath string, opts readDirOpts) (entries []string, err er continue } case data.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0: - name = name + SlashSeparator + name += SlashSeparator } count-- diff --git a/internal/disk/directio_unsupported.go b/internal/disk/directio_unsupported.go index 2d7555726..6c579aa47 100644 --- a/internal/disk/directio_unsupported.go +++ b/internal/disk/directio_unsupported.go @@ -63,6 +63,6 @@ func DisableDirectIO(f *os.File) error { // AlignedBlock simply returns an unaligned buffer // for systems that do not support DirectIO. -func AlignedBlock(BlockSize int) []byte { - return make([]byte, BlockSize) +func AlignedBlock(blockSize int) []byte { + return make([]byte, blockSize) } diff --git a/internal/lock/lock_windows.go b/internal/lock/lock_windows.go index dccca6779..57bc2f533 100644 --- a/internal/lock/lock_windows.go +++ b/internal/lock/lock_windows.go @@ -81,11 +81,10 @@ func lockedOpenFile(path string, flag int, perm os.FileMode, lockType uint32) (* // acquire a write lock. func TryLockedOpenFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { var lockType uint32 = lockFileFailImmediately | lockFileExclusiveLock - switch flag { - case syscall.O_RDONLY: + if flag == syscall.O_RDONLY { // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-lockfileex //lint:ignore SA4016 Reasons - lockType = lockFileFailImmediately | 0 // Set this to enable shared lock and fail immediately. + lockType = lockFileFailImmediately // Set this to enable shared lock and fail immediately. } return lockedOpenFile(path, flag, perm, lockType) } @@ -94,8 +93,7 @@ func TryLockedOpenFile(path string, flag int, perm os.FileMode) (*LockedFile, er // the file from concurrent access. func LockedOpenFile(path string, flag int, perm os.FileMode) (*LockedFile, error) { var lockType uint32 = lockFileExclusiveLock - switch flag { - case syscall.O_RDONLY: + if flag == syscall.O_RDONLY { // https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-lockfileex lockType = 0 // Set this to enable shared lock. } @@ -239,15 +237,13 @@ func lockFile(fd syscall.Handle, flags uint32) error { } err := lockFileEx(fd, flags, 1, 0, &syscall.Overlapped{}) - if err == nil { + if err == nil || err == errLockViolation { return nil - } else if err.Error() == "The process cannot access the file because another process has locked a portion of the file." { - return ErrAlreadyLocked - } else if err != errLockViolation { - return err } - - return nil + if err.Error() == "The process cannot access the file because another process has locked a portion of the file." { + return ErrAlreadyLocked + } + return err } func lockFileEx(h syscall.Handle, flags, locklow, lockhigh uint32, ol *syscall.Overlapped) (err error) { diff --git a/internal/lock/lock_windows_test.go b/internal/lock/lock_windows_test.go index 84bcc017a..5ed011833 100644 --- a/internal/lock/lock_windows_test.go +++ b/internal/lock/lock_windows_test.go @@ -51,10 +51,10 @@ func TestFixLongPath(t *testing.T) { {`\\?\c:\long\foo.txt`, `\\?\c:\long\foo.txt`}, {`\\?\c:\long/foo.txt`, `\\?\c:\long/foo.txt`}, } { - in := strings.Replace(test.in, "long", veryLong, -1) - want := strings.Replace(test.want, "long", veryLong, -1) + in := strings.ReplaceAll(test.in, "long", veryLong) + want := strings.ReplaceAll(test.want, "long", veryLong) if got := fixLongPath(in); got != want { - got = strings.Replace(got, veryLong, "long", -1) + got = strings.ReplaceAll(got, veryLong, "long") t.Errorf("fixLongPath(%q) = %q; want %q", test.in, got, test.want) } }