mirror of
https://github.com/munki/munki.git
synced 2026-05-20 13:18:33 -05:00
Add availableDiskSpace function to shared/info.swift
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import CoreServices.LaunchServices
|
||||
import Darwin
|
||||
import Foundation
|
||||
import IOKit
|
||||
|
||||
@@ -257,3 +258,18 @@ func hasIntel64Support() -> Bool {
|
||||
}
|
||||
return buffer[0] == 1
|
||||
}
|
||||
|
||||
func availableDiskSpace(volumePath _: String = "/") -> Int {
|
||||
// Returns available diskspace in KBytes.
|
||||
// Value should be very close to `df -k` output
|
||||
// Returns negative values of there is an error
|
||||
let buffer = UnsafeMutablePointer<statvfs>.allocate(capacity: 1024)
|
||||
defer { buffer.deallocate() }
|
||||
let err = statvfs("/", buffer)
|
||||
if err != 0 {
|
||||
return -1
|
||||
}
|
||||
let f_frsize = Int(buffer.pointee.f_frsize)
|
||||
let f_bavail = Int(buffer.pointee.f_bavail)
|
||||
return Int(f_frsize * f_bavail / 1024)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user