-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed the issue with the windows build - Added a strategy to test all build targets during PR
- Loading branch information
Showing
4 changed files
with
80 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//go:build linux || darwin | ||
// +build linux darwin | ||
|
||
package cacheservice | ||
|
||
import ( | ||
"syscall" | ||
|
||
"github.com/Parallels/prl-devops-service/errors" | ||
) | ||
|
||
func (cs *CacheService) getFreeDiskSpace() (int64, error) { | ||
// We will be getting the free disk space from the disk | ||
var stat syscall.Statfs_t | ||
err := syscall.Statfs(cs.cacheFolder, &stat) | ||
if err != nil { | ||
return 0, errors.NewFromErrorWithCode(err, 500) | ||
} | ||
|
||
// Available blocks * size per block = available space in bytes | ||
diskFreeSpaceInBytes := int64(stat.Bavail) * int64(stat.Bsize) | ||
diskFreeSpaceInMb := diskFreeSpaceInBytes / (1024 * 1024) | ||
|
||
return diskFreeSpaceInMb, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cacheservice | ||
|
||
import ( | ||
"errors" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
func (cs *CacheService) getFreeDiskSpace() (int64, error) { | ||
// Convert Go string to UTF16 pointer | ||
lpDirectoryName, err := syscall.UTF16PtrFromString(cs.cacheFolder) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
// Load the kernel32 DLL and find the procedure | ||
kernel32 := syscall.MustLoadDLL("kernel32.dll") | ||
defer kernel32.Release() | ||
|
||
procGetDiskFreeSpaceExW := kernel32.MustFindProc("GetDiskFreeSpaceExW") | ||
|
||
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes uint64 | ||
|
||
// Call the Windows API | ||
r, _, callErr := procGetDiskFreeSpaceExW.Call( | ||
uintptr(unsafe.Pointer(lpDirectoryName)), | ||
uintptr(unsafe.Pointer(&freeBytesAvailable)), | ||
uintptr(unsafe.Pointer(&totalNumberOfBytes)), | ||
uintptr(unsafe.Pointer(&totalNumberOfFreeBytes)), | ||
) | ||
if r == 0 { | ||
// The call failed | ||
if callErr != syscall.Errno(0) { | ||
return 0, callErr | ||
} | ||
return 0, errors.New("GetDiskFreeSpaceExW failed, unknown error") | ||
} | ||
|
||
// freeBytesAvailable is the number of bytes available to the *caller* (which | ||
// can differ from the total free bytes if quotas are in use, but in most | ||
// cases is the same). | ||
// Convert bytes -> MB | ||
diskFreeSpaceInMB := freeBytesAvailable / (1024 * 1024) | ||
|
||
return int64(diskFreeSpaceInMB), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters