Fixed windows compatibility
Some checks failed
Run Integration Tests / test (push) Failing after 10m8s
Some checks failed
Run Integration Tests / test (push) Failing after 10m8s
This commit is contained in:
parent
ed588e8764
commit
8dbfaae1b6
4 changed files with 64 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,4 +6,5 @@ cache/
|
|||
*.min.js
|
||||
*.min.css
|
||||
qgato
|
||||
qgato.exe
|
||||
test.py
|
23
config.go
23
config.go
|
@ -4,10 +4,8 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
|
@ -537,27 +535,6 @@ func parseMaxUsageDrive(value string, cachePath string) uint64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
// Get total disk space of the system where cachePath resides
|
||||
func getTotalDiskSpace(cachePath string) uint64 {
|
||||
var stat syscall.Statfs_t
|
||||
|
||||
// Get filesystem stats for the cache path
|
||||
absPath, err := filepath.Abs(cachePath)
|
||||
if err != nil {
|
||||
printErr("Failed to resolve absolute path for: %s", cachePath)
|
||||
return 0
|
||||
}
|
||||
|
||||
err = syscall.Statfs(absPath, &stat)
|
||||
if err != nil {
|
||||
printErr("Failed to retrieve filesystem stats for: %s", absPath)
|
||||
return 0
|
||||
}
|
||||
|
||||
// Total disk space in bytes
|
||||
return stat.Blocks * uint64(stat.Bsize)
|
||||
}
|
||||
|
||||
// Helper to format bytes back to human-readable string
|
||||
func formatMaxUsage(bytes uint64) string {
|
||||
const GiB = 1024 * 1024 * 1024
|
||||
|
|
27
disk.go
Normal file
27
disk.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getTotalDiskSpace(cachePath string) uint64 {
|
||||
var stat syscall.Statfs_t
|
||||
|
||||
absPath, err := filepath.Abs(cachePath)
|
||||
if err != nil {
|
||||
printErr("Failed to resolve absolute path for: %s", cachePath)
|
||||
return 0
|
||||
}
|
||||
|
||||
err = syscall.Statfs(absPath, &stat)
|
||||
if err != nil {
|
||||
printErr("Failed to retrieve filesystem stats for: %s", absPath)
|
||||
return 0
|
||||
}
|
||||
|
||||
return stat.Blocks * uint64(stat.Bsize)
|
||||
}
|
36
disk_win.go
Normal file
36
disk_win.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func getTotalDiskSpace(path string) uint64 {
|
||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
getDiskFreeSpaceExW := kernel32.NewProc("GetDiskFreeSpaceExW")
|
||||
|
||||
lpDirectoryName, err := syscall.UTF16PtrFromString(path)
|
||||
if err != nil {
|
||||
printErr("Failed to encode path for Windows API: %v", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64
|
||||
|
||||
r1, _, err := getDiskFreeSpaceExW.Call(
|
||||
uintptr(unsafe.Pointer(lpDirectoryName)),
|
||||
uintptr(unsafe.Pointer(&freeBytesAvailable)),
|
||||
uintptr(unsafe.Pointer(&totalNumberOfBytes)),
|
||||
uintptr(unsafe.Pointer(&totalNumberOfFreeBytes)),
|
||||
)
|
||||
|
||||
if r1 == 0 {
|
||||
printErr("GetDiskFreeSpaceExW failed: %v", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
return totalNumberOfBytes
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue