summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2017-05-31 11:53:59 +0200
committerDamiano Galassi <[email protected]>2017-05-31 11:53:59 +0200
commit4f23ed561867bc65707121a786679a441705269f (patch)
tree7f309cd2e07446ac77f74b39f6fbfcba7b3484ed /macosx
parent1f2769e451fba3881067ca5268330fa43789ceb1 (diff)
MacGui: use a newer api to get the disk free space.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBQueueController.m27
1 files changed, 22 insertions, 5 deletions
diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m
index f6da396bb..e26b2dc14 100644
--- a/macosx/HBQueueController.m
+++ b/macosx/HBQueueController.m
@@ -540,15 +540,32 @@
#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;
}