From 7ee889bb0d0dcf0292745975454ed53d94cdb0a9 Mon Sep 17 00:00:00 2001 From: DRON-666 <64691982+DRON-666@users.noreply.github.com> Date: Mon, 29 Apr 2024 01:25:25 +0300 Subject: [PATCH] Use S_FALSE and MaxInt --- internal/fs/vss_windows.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/fs/vss_windows.go b/internal/fs/vss_windows.go index 91c60c4ba..e8c5dc561 100644 --- a/internal/fs/vss_windows.go +++ b/internal/fs/vss_windows.go @@ -5,6 +5,7 @@ package fs import ( "fmt" + "math" "path/filepath" "runtime" "strings" @@ -24,6 +25,7 @@ type HRESULT uint //nolint:golint const ( S_OK HRESULT = 0x00000000 + S_FALSE HRESULT = 0x00000001 E_ACCESSDENIED HRESULT = 0x80070005 E_OUTOFMEMORY HRESULT = 0x8007000E E_INVALIDARG HRESULT = 0x80070057 @@ -640,7 +642,7 @@ func (vssAsync *IVSSAsync) QueryStatus() (HRESULT, uint32) { // WaitUntilAsyncFinished waits until either the async call is finished or // the given timeout is reached. func (vssAsync *IVSSAsync) WaitUntilAsyncFinished(timeout time.Duration) error { - const maxTimeout = 2147483647 * time.Millisecond + const maxTimeout = math.MaxInt32 * time.Millisecond if timeout > maxTimeout { timeout = maxTimeout } @@ -740,7 +742,7 @@ func (vssEnum *IVssEnumObject) Next(count uint, props unsafe.Pointer) (uint, err result, _, _ := syscall.Syscall6(vssEnum.getVTable().next, 4, uintptr(unsafe.Pointer(vssEnum)), uintptr(count), uintptr(props), uintptr(unsafe.Pointer(&fetched)), 0, 0) - if result == 1 { + if HRESULT(result) == S_FALSE { return uint(fetched), nil } @@ -791,8 +793,8 @@ func initializeVssCOMInterface() (*ole.IUnknown, error) { // ensure COM is initialized before use if err = ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); err != nil { - // CoInitializeEx returns 1 if COM is already initialized - if oleErr, ok := err.(*ole.OleError); !ok || oleErr.Code() != 1 { + // CoInitializeEx returns S_FALSE if COM is already initialized + if oleErr, ok := err.(*ole.OleError); !ok || HRESULT(oleErr.Code()) != S_FALSE { return nil, err } }