2
0
Files
gitcaddy-runner/internal/pkg/envcheck/disk_windows.go
GitCaddy e0feb6bd4e
Some checks failed
CI / build-and-test (push) Failing after 30s
Release / build (amd64, darwin) (push) Failing after 1m20s
Release / build (arm64, darwin) (push) Failing after 1m32s
Release / build (amd64, windows) (push) Failing after 1m40s
Release / build (arm64, linux) (push) Successful in 1m30s
Release / release (push) Has been cancelled
Release / build (amd64, linux) (push) Has been cancelled
chore: Remove gitea-vet from build process
Use standard go vet instead of gitea-vet for copyright checks.
This allows MarketAlly copyright headers in new files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 09:53:17 +00:00

58 lines
1.4 KiB
Go

// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT
//go:build windows
package envcheck
import (
"path/filepath"
"golang.org/x/sys/windows"
)
// detectDiskSpace detects disk space on the specified path's drive (Windows version)
// If path is empty, defaults to "C:\"
func detectDiskSpace(path string) *DiskInfo {
if path == "" {
path = "C:\\"
}
// Resolve to absolute path
absPath, err := filepath.Abs(path)
if err != nil {
absPath = "C:\\"
}
// Extract drive letter (e.g., "D:\" from "D:\builds\runner")
drivePath := filepath.VolumeName(absPath) + "\\"
if drivePath == "\\" {
drivePath = "C:\\"
}
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64
pathPtr := windows.StringToUTF16Ptr(drivePath)
err = windows.GetDiskFreeSpaceEx(pathPtr, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes)
if err != nil {
// Fallback to C: drive
pathPtr = windows.StringToUTF16Ptr("C:\\")
err = windows.GetDiskFreeSpaceEx(pathPtr, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes)
if err != nil {
return nil
}
drivePath = "C:\\"
}
used := totalNumberOfBytes - totalNumberOfFreeBytes
usedPercent := float64(used) / float64(totalNumberOfBytes) * 100
return &DiskInfo{
Path: drivePath,
Total: totalNumberOfBytes,
Free: totalNumberOfFreeBytes,
Used: used,
UsedPercent: usedPercent,
}
}