mirror of
https://github.com/transmission/transmission
synced 2025-03-03 18:25:35 +00:00
simplify the remaining disk space checking code
This commit is contained in:
parent
8d5ce92d38
commit
f14ee4fd6b
2 changed files with 13 additions and 16 deletions
|
@ -2223,6 +2223,7 @@
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
||||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
|
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = NO;
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.4;
|
MACOSX_DEPLOYMENT_TARGET = 10.4;
|
||||||
PREBINDING = NO;
|
PREBINDING = NO;
|
||||||
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
|
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
|
||||||
|
@ -2239,6 +2240,7 @@
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
||||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
|
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
|
||||||
|
GCC_WARN_UNUSED_VARIABLE = NO;
|
||||||
MACOSX_DEPLOYMENT_TARGET = 10.4;
|
MACOSX_DEPLOYMENT_TARGET = 10.4;
|
||||||
PREBINDING = NO;
|
PREBINDING = NO;
|
||||||
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
|
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
|
||||||
|
|
|
@ -536,11 +536,14 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
NSFileManager * fileManager = [NSFileManager defaultManager];
|
NSFileManager * fileManager = [NSFileManager defaultManager];
|
||||||
|
NSString * downloadFolder = [self downloadFolder];
|
||||||
|
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
|
||||||
|
|
||||||
NSString * volumeName;
|
NSString * volumeName;
|
||||||
if ((volumeName = [[fileManager componentsToDisplayForPath: [self downloadFolder]] objectAtIndex: 0]))
|
if ((volumeName = [[fileManager componentsToDisplayForPath: downloadFolder] objectAtIndex: 0]))
|
||||||
{
|
{
|
||||||
NSDictionary * systemAttributes = [fileManager fileSystemAttributesAtPath: [self downloadFolder]];
|
NSDictionary * systemAttributes = onLeopard ? [fileManager attributesOfFileSystemForPath: downloadFolder error: NULL]
|
||||||
|
: [fileManager fileSystemAttributesAtPath: downloadFolder];
|
||||||
uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue], neededSpace = 0;
|
uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue], neededSpace = 0;
|
||||||
|
|
||||||
[self updateFileStat];
|
[self updateFileStat];
|
||||||
|
@ -553,21 +556,13 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||||
{
|
{
|
||||||
tr_file * file = &fInfo->files[i];
|
tr_file * file = &fInfo->files[i];
|
||||||
|
|
||||||
NSString * path = [[self downloadFolder] stringByAppendingPathComponent: [NSString stringWithUTF8String: file->name]];
|
|
||||||
if ([fileManager fileExistsAtPath: path])
|
|
||||||
{
|
|
||||||
NSDictionary * fileAttributes = [NSApp isOnLeopardOrBetter] ? [fileManager attributesOfItemAtPath: path error: NULL]
|
|
||||||
: [fileManager fileAttributesAtPath: path traverseLink: NO];
|
|
||||||
if (!fileAttributes)
|
|
||||||
{
|
|
||||||
NSLog(@"Problems getting file information for \"%@\".", path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
neededSpace += file->length - [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
neededSpace += file->length;
|
neededSpace += file->length;
|
||||||
|
|
||||||
|
NSString * path = [downloadFolder stringByAppendingPathComponent: [NSString stringWithUTF8String: file->name]];
|
||||||
|
NSDictionary * fileAttributes = onLeopard ? [fileManager attributesOfItemAtPath: path error: NULL]
|
||||||
|
: [fileManager fileAttributesAtPath: path traverseLink: NO];
|
||||||
|
if (fileAttributes)
|
||||||
|
neededSpace -= [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue