From bc86484de9483a396120c9a56a1eb83961e3afc5 Mon Sep 17 00:00:00 2001 From: cheekiatng Date: Thu, 28 May 2015 10:24:11 +0800 Subject: [PATCH] Add error log and fixed returned object class --- apidoc/Titanium/Filesystem/File.yml | 13 ++++++------ iphone/Classes/TiFilesystemFileProxy.m | 28 +++++++++----------------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/apidoc/Titanium/Filesystem/File.yml b/apidoc/Titanium/Filesystem/File.yml index fc156ba60d1..fd55758baa4 100644 --- a/apidoc/Titanium/Filesystem/File.yml +++ b/apidoc/Titanium/Filesystem/File.yml @@ -191,11 +191,12 @@ methods: - name: getProtectionKey summary: | Returns the protection key value of this file object. Can be one of the following - Titanium.Filesystem constants: - IOS_FILE_PROTECTION_NONE - IOS_FILE_PROTECTION_COMPLETE - IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN - IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION + constants: + Titanium.Filesystem.IOS_FILE_PROTECTION_NONE + Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE + Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN + Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION + Returns `null` if there's an error. returns: type: String platforms: [iphone, ipad] @@ -287,7 +288,7 @@ methods: - name: setProtectionKey summary: Sets the protection key as an attribute to the file identified by this file object. description: | - Returns `true` if successfully set. Otherwise `false`. + Returns `true` if successfully set. Returns `false` if failed. returns: type: Boolean parameters: diff --git a/iphone/Classes/TiFilesystemFileProxy.m b/iphone/Classes/TiFilesystemFileProxy.m index 0dd2cf840ec..8db1a8b4cbf 100644 --- a/iphone/Classes/TiFilesystemFileProxy.m +++ b/iphone/Classes/TiFilesystemFileProxy.m @@ -153,34 +153,26 @@ -(id)spaceAvailable:(id)args return [resultDict objectForKey:NSFileSystemFreeSize]; } --(id)getProtectionKey:(id)args +-(NSString *)getProtectionKey:(id)args { NSError *error = nil; NSDictionary * resultDict = [fm attributesOfItemAtPath:path error:&error]; - if (error!=nil) return NUMBOOL(NO); - NSString *obj = [resultDict objectForKey:NSFileProtectionKey]; - if (obj != nil) { - if ([obj isEqualToString:NSFileProtectionNone]) { - return @"IOS_FILE_PROTECTION_NONE"; - } - if ([obj isEqualToString:NSFileProtectionComplete]) { - return @"IOS_FILE_PROTECTION_COMPLETE"; - } - if ([obj isEqualToString:NSFileProtectionCompleteUnlessOpen]) { - return @"IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN"; - } - if ([obj isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication]) { - return @"IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION"; - } + if (error != nil) { + NSLog(@"[ERROR] Error getting protection key: %@", [TiUtils messageFromError:error]); + return nil; } + return [resultDict objectForKey:NSFileProtectionKey]; } --(id)setProtectionKey:(id)args +-(NSNumber *)setProtectionKey:(id)args { ENSURE_SINGLE_ARG(args, NSString); NSError *error = nil; BOOL result = [fm setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:args, NSFileProtectionKey, nil] ofItemAtPath:path error:&error]; - if (error!=nil) return NUMBOOL(NO); + if (error != nil) { + NSLog(@"[ERROR] Error setting protection key: %@", [TiUtils messageFromError:error]); + return NUMBOOL(NO); + } return NUMBOOL(YES); }