]> granicus.if.org Git - handbrake/commitdiff
MacGui: use a newer api to get the disk free space.
authorDamiano Galassi <damiog@gmail.com>
Wed, 31 May 2017 09:53:59 +0000 (11:53 +0200)
committerDamiano Galassi <damiog@gmail.com>
Wed, 31 May 2017 09:53:59 +0000 (11:53 +0200)
macosx/HBQueueController.m

index f6da396bb00825e5470417d0af06e6418ea159ea..e26b2dc148382733066c95a30dc8ea90b317daee 100644 (file)
 #pragma mark -
 #pragma mark Queue Job Processing
 
-#define ALMOST_5GB 5000000000
+#define ALMOST_2GB 2000000000
 
 - (BOOL)_isDiskSpaceLowAtURL:(NSURL *)url
 {
-    NSDictionary *dict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:url.URLByDeletingLastPathComponent.path error:NULL];
-    long long freeSpace = [dict[NSFileSystemFreeSize] longLongValue];
-    if (freeSpace < ALMOST_5GB) {
-        return YES;
+    NSURL *volumeURL = nil;
+    NSDictionary<NSURLResourceKey, id> *attrs = [url resourceValuesForKeys:@[NSURLIsVolumeKey, NSURLVolumeURLKey] error:NULL];
+
+    volumeURL = [attrs[NSURLIsVolumeKey] boolValue] ? url : attrs[NSURLVolumeURLKey];
+
+    if (volumeURL)
+    {
+        if ([volumeURL respondsToSelector:@selector(removeCachedResourceValueForKey:)])
+        {
+            [volumeURL removeCachedResourceValueForKey:NSURLVolumeAvailableCapacityKey];
+        }
+        attrs = [volumeURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityKey] error:NULL];
+
+        if (attrs[NSURLVolumeAvailableCapacityKey])
+        {
+            if ([attrs[NSURLVolumeAvailableCapacityKey] longLongValue] < ALMOST_2GB)
+            {
+                return YES;
+            }
+        }
     }
+
     return NO;
 }