mirror of
https://github.com/octoleo/restic.git
synced 2024-12-28 04:56:04 +00:00
36 lines
719 B
Go
36 lines
719 B
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package restorer
|
|
|
|
import (
|
|
"math"
|
|
"syscall"
|
|
"testing"
|
|
"unsafe"
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func getBlockCount(t *testing.T, filename string) int64 {
|
|
libkernel32 := windows.NewLazySystemDLL("kernel32.dll")
|
|
err := libkernel32.Load()
|
|
rtest.OK(t, err)
|
|
proc := libkernel32.NewProc("GetCompressedFileSizeW")
|
|
err = proc.Find()
|
|
rtest.OK(t, err)
|
|
|
|
namePtr, err := syscall.UTF16PtrFromString(filename)
|
|
rtest.OK(t, err)
|
|
|
|
result, _, _ := proc.Call(uintptr(unsafe.Pointer(namePtr)), 0)
|
|
|
|
const invalidFileSize = uintptr(4294967295)
|
|
if result == invalidFileSize {
|
|
return -1
|
|
}
|
|
|
|
return int64(math.Ceil(float64(result) / 512))
|
|
}
|