You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/05/08 23:36:35 UTC

ios commit: Fixes CB-471 - LocalFileSystem.PERSISTENT "do not back up" file attribute iOS

Updated Branches:
  refs/heads/master 6c458353b -> c6dc03acf


Fixes CB-471 - LocalFileSystem.PERSISTENT "do not back up" file attribute iOS


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/c6dc03ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/c6dc03ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/c6dc03ac

Branch: refs/heads/master
Commit: c6dc03acfee633c4ea84e0bc6a94e92a2d2993ef
Parents: 6c45835
Author: Shazron Abdullah <sh...@apache.org>
Authored: Tue May 8 14:35:55 2012 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue May 8 14:36:25 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVFile.m |   42 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/c6dc03ac/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 1e5a15f..08e184d 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -23,7 +23,7 @@
 #import "JSONKit.h"
 #import "NSData+Base64.h"
 #import <MobileCoreServices/MobileCoreServices.h>
-
+#import "sys/xattr.h"
 
 @implementation CDVFile
 
@@ -516,6 +516,46 @@
 	[fileMgr release];
 }
 
+/*
+ * set MetaData of entry
+ * Currently we only support "com.apple.MobileBackup" (boolean)
+ */
+- (void) setMetadata:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+	NSString* callbackId = [arguments pop];
+    VERIFY_ARGUMENTS(arguments, 1, callbackId)
+    
+    // arguments
+	NSString* filePath = [arguments objectAtIndex:0];
+    CDVPluginResult* result = nil;
+    BOOL ok = NO;
+    
+    // we only care about this iCloud key for now. 
+    // set to 1/true to skip backup, set to 0/false to back it up (effectively removing the attribute)
+    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 (ok) {
+		result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+		[self writeJavascript:[result toSuccessCallbackString:callbackId]];
+
+    } else {
+		result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
+		[self writeJavascript:[result toErrorCallbackString:callbackId]];
+    }
+}
+
 /* removes the directory or file entry
  * IN: 
  * NSArray* arguments