Some checks failed
CI / build-and-test (push) Has been cancelled
Release / build (amd64, darwin) (push) Has been cancelled
Release / build (amd64, linux) (push) Has been cancelled
Release / build (amd64, windows) (push) Has been cancelled
Release / build (arm64, darwin) (push) Has been cancelled
Release / build (arm64, linux) (push) Has been cancelled
Release / release (push) Has been cancelled
- Add visionOS/xrOS SDK detection for Vision Pro development - Add PowerShell version detection (pwsh and powershell) with actual versions - Detect disk space on working directory filesystem (not just root) - Useful for runners using external/USB drives for builds - Add watchOS and tvOS suggested labels - Refactor disk detection to accept path parameter 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
//go:build windows
|
|
|
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
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,
|
|
}
|
|
}
|