Parcourir la source

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 il y a 1 an
Parent
commit
32ec6c17b5
1 fichiers modifiés avec 9 ajouts et 13 suppressions
  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;
         }
     }