0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-19 20:32:15 +02:00

libobs: Fix free disk space calculation on macOS (#10187)

New space availability keys seem to have very specific file system
requirements not documented anywhere. Using the opportunistic free
space key opportunistically (and falling back on the legacy value
otherwise) should always yield a "good-enough" free disk space value.
This commit is contained in:
Patrick Heyer 2024-02-04 00:35:09 +01:00 committed by GitHub
parent b79ba49252
commit 32ec6c17b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -363,23 +363,19 @@ int64_t os_get_free_space(const char *path)
if (path) {
NSURL *fileURL = [NSURL fileURLWithPath:@(path)];
NSDictionary *values = [fileURL resourceValuesForKeys:@[NSURLVolumeIsLocalKey] error:nil];
NSArray *availableCapacityKeys = @[
NSURLVolumeAvailableCapacityKey, NSURLVolumeAvailableCapacityForImportantUsageKey,
NSURLVolumeAvailableCapacityForOpportunisticUsageKey
];
BOOL isLocalVolume = [values[NSURLVolumeIsLocalKey] boolValue];
NSDictionary *values = [fileURL resourceValuesForKeys:availableCapacityKeys error:nil];
NSURLResourceKey volumeKey;
NSNumber *availableOpportunisticSpace = values[NSURLVolumeAvailableCapacityForOpportunisticUsageKey];
NSNumber *availableSpace = values[NSURLVolumeAvailableCapacityKey];
if (isLocalVolume) {
volumeKey = NSURLVolumeAvailableCapacityForOpportunisticUsageKey;
if (availableOpportunisticSpace.longValue > 0) {
return availableOpportunisticSpace.longValue;
} else {
volumeKey = NSURLVolumeAvailableCapacityKey;
}
values = [fileURL resourceValuesForKeys:@[volumeKey] error:nil];
NSNumber *availableSpace = values[volumeKey];
if (availableSpace) {
return availableSpace.longValue;
}
}