Updated Branches:
  refs/heads/master 850a08b65 -> 32612280d

Enhanced CB-471 - LocalFileSystem.PERSISTENT "do not back up" file attribute 
iOS. Supports new iOS 5.1 iCloud Backup attribute (the old way is deprecated, 
and only for iOS 5.0.1)


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/32612280
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/32612280
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/32612280

Branch: refs/heads/master
Commit: 32612280dae96980ecc393ef35348e728dcddd3f
Parents: 850a08b
Author: Shazron Abdullah <[email protected]>
Authored: Wed Jun 20 11:25:23 2012 -0700
Committer: Shazron Abdullah <[email protected]>
Committed: Wed Jun 20 11:25:23 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVFile.m |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/32612280/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 76d3d8a..7730cfc 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -23,6 +23,7 @@
 #import "JSONKit.h"
 #import "NSData+Base64.h"
 #import <MobileCoreServices/MobileCoreServices.h>
+#import "CDVAvailability.h"
 #import "sys/xattr.h"
 
 @implementation CDVFile
@@ -529,14 +530,23 @@
     NSString* iCloudBackupExtendedAttributeKey = @"com.apple.MobileBackup";
     id iCloudBackupExtendedAttributeValue = [options 
objectForKey:iCloudBackupExtendedAttributeKey];
     
-    if (iCloudBackupExtendedAttributeValue != nil && 
-        [iCloudBackupExtendedAttributeValue isKindOfClass:[NSNumber class]]) {
-        
-        u_int8_t value = [iCloudBackupExtendedAttributeValue intValue];
-        if (value == 0) { // remove the attribute (allow backup, the default)
-            ok = (removexattr([filePath fileSystemRepresentation], 
[iCloudBackupExtendedAttributeKey cStringUsingEncoding:NSUTF8StringEncoding], 
0) == 0);
-        } else { // set the attribute (skip backup)
-            ok = (setxattr([filePath fileSystemRepresentation], 
[iCloudBackupExtendedAttributeKey cStringUsingEncoding:NSUTF8StringEncoding], 
&value, sizeof(value), 0, 0) == 0);
+    if (iCloudBackupExtendedAttributeValue != nil && 
[iCloudBackupExtendedAttributeValue isKindOfClass:[NSNumber class]])
+    {
+        if (IsAtLeastiOSVersion(@"5.1")) 
+        {
+            NSURL* url = [NSURL fileURLWithPath:filePath];
+            NSError* error = nil;
+            
+            ok = [url setResourceValue: [NSNumber numberWithBool: 
[iCloudBackupExtendedAttributeValue boolValue]] forKey: 
NSURLIsExcludedFromBackupKey error:&error];
+        }
+        else // below 5.1 (deprecated - only really supported in 5.01)
+        {
+            u_int8_t value = [iCloudBackupExtendedAttributeValue intValue];
+            if (value == 0) { // remove the attribute (allow backup, the 
default)
+                ok = (removexattr([filePath fileSystemRepresentation], 
[iCloudBackupExtendedAttributeKey cStringUsingEncoding:NSUTF8StringEncoding], 
0) == 0);
+            } else { // set the attribute (skip backup)
+                ok = (setxattr([filePath fileSystemRepresentation], 
[iCloudBackupExtendedAttributeKey cStringUsingEncoding:NSUTF8StringEncoding], 
&value, sizeof(value), 0, 0) == 0);
+            }
         }
     }
     

Reply via email to