Переглянути джерело

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.
Patrick Heyer 1 рік тому
батько
коміт
32ec6c17b5
1 змінених файлів з 9 додано та 13 видалено
  1. 9 13
      libobs/util/platform-cocoa.m

+ 9 - 13
libobs/util/platform-cocoa.m

@@ -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;
         }
     }