cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [7/13] ios commit: [CB-2213] Added NATIVE_URI to three methods.
Date Tue, 12 Feb 2013 03:14:33 GMT
[CB-2213] Added NATIVE_URI to three methods.

The three methods are FileEntry.remove, FileEntry.setMetadata, and FileReader.readAsText.


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

Branch: refs/heads/master
Commit: 2cf83698d68d3ccfca0dbfed70b5864f56533865
Parents: 2af83b1
Author: Max Woghiren <max.woghiren@gmail.com>
Authored: Wed Jan 16 15:09:58 2013 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Feb 11 21:06:23 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVFile.m |   74 +++++++++++++++----------------------
 1 files changed, 30 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/2cf83698/CordovaLib/Classes/CDVFile.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFile.m b/CordovaLib/Classes/CDVFile.m
index 8fee45a..f3d8872 100644
--- a/CordovaLib/Classes/CDVFile.m
+++ b/CordovaLib/Classes/CDVFile.m
@@ -548,34 +548,29 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
     // arguments
     NSString* filePath = [command.arguments objectAtIndex:0];
     NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:nil];
-
-    // return unsupported result for assets-library URLs
-    if ([filePath hasPrefix:kCDVAssetsLibraryPrefix]) {
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION
messageAsString:@"setMetadata not supported for assets-library URLs."];
-        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
-        return;
-    }
-
     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]]) {
-        if (IsAtLeastiOSVersion(@"5.1")) {
-            NSURL* url = [NSURL fileURLWithPath:filePath];
-            NSError* __autoreleasing 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);
+    // setMetadata doesn't make sense for asset library files
+    if (![filePath hasPrefix:kCDVAssetsLibraryPrefix]) {
+        // 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]]) {
+            if (IsAtLeastiOSVersion(@"5.1")) {
+                NSURL* url = [NSURL fileURLWithPath:filePath];
+                NSError* __autoreleasing 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);
+                }
             }
         }
     }
@@ -594,26 +589,21 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
  *	0 - NSString* fullPath
  *
  * returns NO_MODIFICATION_ALLOWED_ERR  if is top level directory or no permission to delete
dir
- * returns INVALID_MODIFICATION_ERR if is dir and is not empty
+ * returns INVALID_MODIFICATION_ERR if is non-empty dir or asset library file
  * returns NOT_FOUND_ERR if file or dir is not found
 */
 - (void)remove:(CDVInvokedUrlCommand*)command
 {
     // arguments
     NSString* fullPath = [command.arguments objectAtIndex:0];
-
-    // return unsupported result for assets-library URLs
-    if ([fullPath hasPrefix:kCDVAssetsLibraryPrefix]) {
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION
messageAsString:@"remove not supported for assets-library URLs."];
-        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
-        return;
-    }
-
     CDVPluginResult* result = nil;
     CDVFileError errorCode = 0;  // !! 0 not currently defined
 
-    // error if try to remove top level (documents or tmp) dir
-    if ([fullPath isEqualToString:self.appDocsPath] || [fullPath isEqualToString:self.appTempPath])
{
+    // return error for assets-library URLs
+    if ([fullPath hasPrefix:kCDVAssetsLibraryPrefix]) {
+        errorCode = INVALID_MODIFICATION_ERR;
+    } else if ([fullPath isEqualToString:self.appDocsPath] || [fullPath isEqualToString:self.appTempPath])
{
+        // error if try to remove top level (documents or tmp) dir
         errorCode = NO_MODIFICATION_ALLOWED_ERR;
     } else {
         NSFileManager* fileMgr = [[NSFileManager alloc] init];
@@ -1045,19 +1035,15 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
         end = [[command.arguments objectAtIndex:3] integerValue];
     }
 
-    // return unsupported result for assets-library URLs
-    if ([argPath hasPrefix:kCDVAssetsLibraryPrefix]) {
-        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_MALFORMED_URL_EXCEPTION
messageAsString:@"readAsText not supported for assets-library URLs."];
-        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
-        return;
-    }
-
     // NSString* encoding = [command.arguments objectAtIndex:2];   // not currently used
     CDVPluginResult* result = nil;
 
     NSFileHandle* file = [NSFileHandle fileHandleForReadingAtPath:argPath];
 
-    if (!file) {
+    if ([argPath hasPrefix:kCDVAssetsLibraryPrefix]) {
+        // can't read assets-library URLs as text
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_READABLE_ERR];
+    } else if (!file) {
         // invalid path entry
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
     } else {


Mime
View raw message