cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject git commit: iOS: Android: Allow third-party plugin registration
Date Fri, 24 Jan 2014 03:36:25 GMT
Updated Branches:
  refs/heads/dev a6575308d -> 590b9303f


iOS: Android: Allow third-party plugin registration


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/590b9303
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/590b9303
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/590b9303

Branch: refs/heads/dev
Commit: 590b9303fd29f5e6d9c2aaa6b1a720c61881a9f4
Parents: a657530
Author: Ian Clelland <iclelland@chromium.org>
Authored: Thu Jan 23 14:14:33 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Thu Jan 23 22:35:50 2014 -0500

----------------------------------------------------------------------
 src/ios/CDVAssetLibraryFilesystem.h |   2 +
 src/ios/CDVAssetLibraryFilesystem.m |  17 +++-
 src/ios/CDVFile.h                   |  19 ++--
 src/ios/CDVFile.m                   | 153 +++++++++++++++++++------------
 src/ios/CDVLocalFilesystem.h        |   1 -
 src/ios/CDVLocalFilesystem.m        |  17 ++--
 6 files changed, 126 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVAssetLibraryFilesystem.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVAssetLibraryFilesystem.h b/src/ios/CDVAssetLibraryFilesystem.h
index 295a3d8..e09e225 100644
--- a/src/ios/CDVAssetLibraryFilesystem.h
+++ b/src/ios/CDVAssetLibraryFilesystem.h
@@ -25,4 +25,6 @@ extern NSString* const kCDVAssetsLibraryScheme;
 @interface CDVAssetLibraryFilesystem : NSObject<CDVFileSystem> {
 }
 
+- (id) initWithName:(NSString *)name;
+
 @end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVAssetLibraryFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVAssetLibraryFilesystem.m b/src/ios/CDVAssetLibraryFilesystem.m
index 09a5461..cca4038 100644
--- a/src/ios/CDVAssetLibraryFilesystem.m
+++ b/src/ios/CDVAssetLibraryFilesystem.m
@@ -29,6 +29,8 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
 NSString* const kCDVAssetsLibraryScheme = @"assets-library";
 
 @implementation CDVAssetLibraryFilesystem
+@synthesize name=_name;
+
 - (CDVPluginResult *)entryForLocalURI:(CDVFilesystemURL *)url
 {
     NSDictionary* entry = [self makeEntryForLocalURL:url];
@@ -36,10 +38,10 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
 }
 
 - (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url {
-    return [self makeEntryForPath:[url.url absoluteString] fileSystem:ASSETS_LIBRARY isDirectory:NO];
+    return [self makeEntryForPath:[url.url absoluteString] fileSystemName:self.name isDirectory:NO];
 }
 
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir
 {
     NSMutableDictionary* dirEntry = [NSMutableDictionary dictionaryWithCapacity:5];
     NSString* lastPart = [fullPath lastPathComponent];
@@ -50,7 +52,8 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
     [dirEntry setObject:[NSNumber numberWithBool:isDir]  forKey:@"isDirectory"];
     [dirEntry setObject:fullPath forKey:@"fullPath"];
     [dirEntry setObject:lastPart forKey:@"name"];
-    [dirEntry setObject: [NSNumber numberWithInt:fsType] forKey: @"filesystem"];
+    [dirEntry setObject: [NSNumber numberWithInt:([fsName isEqualToString:@"temporary"] ?
0 : 1)] forKey: @"filesystem"];
+    [dirEntry setObject:fsName forKey: @"filesystemName"];
 
     return dirEntry;
 }
@@ -83,6 +86,14 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
     return mimeType;
 }
 
+- (id)initWithName:(NSString *)name
+{
+    if (self) {
+        _name = name;
+    }
+    return self;
+}
+
 - (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath
options:(NSDictionary *)options
 {
     // return unsupported result for assets-library URLs

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 0693f68..85a76b0 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -40,16 +40,9 @@ enum CDVFileError {
 };
 typedef int CDVFileError;
 
-enum CDVFileSystemType {
-    TEMPORARY = 0,
-    PERSISTENT = 1,
-    ASSETS_LIBRARY = 2,
-};
-typedef int CDVFileSystemType;
-
 @interface CDVFilesystemURL : NSObject  {
     NSURL *_url;
-    CDVFileSystemType _fileSystemType;
+    NSString *_fileSystemName;
     NSString *_fullPath;
 }
 
@@ -60,7 +53,7 @@ typedef int CDVFileSystemType;
 
 
 @property (atomic) NSURL *url;
-@property (atomic) CDVFileSystemType fileSystemType;
+@property (atomic) NSString *fileSystemName;
 @property (atomic) NSString *fullPath;
 
 @end
@@ -85,6 +78,8 @@ typedef int CDVFileSystemType;
 
 - (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)url;
 
+@property (nonatomic,strong) NSString *name;
+
 @optional
 - (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURI;
 - (CDVFilesystemURL *)URLforFilesystemPath:(NSString *)path;
@@ -103,12 +98,16 @@ typedef int CDVFileSystemType;
 }
 
 - (NSNumber*)checkFreeDiskSpace:(NSString*)appPath;
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir;
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir;
 - (NSDictionary *)makeEntryForURL:(NSURL *)URL;
 - (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath;
 
 - (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL;
 
+/* Native Registration API */
+- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs;
+- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName;
+
 /* Exec API */
 - (void)requestFileSystem:(CDVInvokedUrlCommand*)command;
 - (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 500acb1..f4f1cbb 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -34,7 +34,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 
 @implementation CDVFilesystemURL
 @synthesize url=_url;
-@synthesize fileSystemType=_fileSystemType;
+@synthesize fileSystemName=_fileSystemName;
 @synthesize fullPath=_fullPath;
 
 - (id) initWithString:(NSString *)strURL
@@ -50,7 +50,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 {
     if ( self = [super init] ) {
         _url = URL;
-        _fileSystemType = [self filesystemTypeForLocalURI:URL];
+        _fileSystemName = [self filesystemNameForLocalURI:URL];
         _fullPath = [self fullPathForLocalURI:URL];
     }
     return self;
@@ -60,20 +60,19 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
  * IN
  *  NSString localURI
  * OUT
- *  int FileSystem type for this URI, or -1 if it is not recognized.
+ *  NSString FileSystem Name for this URI, or nil if it is not recognized.
  */
-- (CDVFileSystemType)filesystemTypeForLocalURI:(NSURL *)uri
+- (NSString *)filesystemNameForLocalURI:(NSURL *)uri
 {
     if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] isEqualToString:@"localhost"])
{
-        if ([[uri path] hasPrefix:@"/temporary"]) {
-            return TEMPORARY;
-        } else if ([[uri path] hasPrefix:@"/persistent"]) {
-            return PERSISTENT;
+        NSArray *pathComponents = [uri pathComponents];
+        if (pathComponents != nil && pathComponents.count > 1) {
+            return [pathComponents objectAtIndex:1];
         }
     } else if ([[uri scheme] isEqualToString:kCDVAssetsLibraryScheme]) {
-        return ASSETS_LIBRARY;
+        return @"assets-library";
     }
-    return -1;
+    return nil;
 }
 
 /*
@@ -85,11 +84,13 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
  */
 - (NSString *)fullPathForLocalURI:(NSURL *)uri
 {
-    int fsType = [self filesystemTypeForLocalURI:uri];
-    if (fsType == TEMPORARY) {
-        return [[uri path] substringFromIndex:10];
-    } else if (fsType == PERSISTENT) {
-        return [[uri path] substringFromIndex:11];
+    if ([[uri scheme] isEqualToString:kCDVFilesystemURLPrefix] && [[uri host] isEqualToString:@"localhost"])
{
+        NSString *path = [uri path];
+        NSRange slashRange = [path rangeOfString:@"/" options:0 range:NSMakeRange(1, path.length-1)];
+        if (slashRange.location == NSNotFound) {
+            return @"";
+        }
+        return [path substringFromIndex:slashRange.location];
     }
     return nil;
 }
@@ -127,7 +128,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 - (void)startLoading
 {
     CDVFilesystemURL* url = [CDVFilesystemURL fileSystemURLWithURL:[[self request] URL]];
-    CDVLocalFilesystem *fs = [filePlugin.fileSystems objectAtIndex:url.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [filePlugin filesystemForURL:url];
     [fs readFileAtURL:url start:0 end:-1 callback:^void(NSData *data, NSString *mimetype,
CDVFileError error) {
         if (!error) {
             NSURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:url.url statusCode:200
HTTPVersion:@"HTTP/1.1"headerFields:@{@"Content-Type": mimetype}];
@@ -154,11 +155,39 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 
 @synthesize appDocsPath, appLibraryPath, appTempPath, persistentPath, temporaryPath, userHasAllowed,
fileSystems=fileSystems_;
 
+- (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs {
+    [fileSystems_ addObject:fs];
+}
+
+- (NSObject<CDVFileSystem> *)fileSystemByName:(NSString *)fsName
+{
+    if (self.fileSystems != nil) {
+        for (NSObject<CDVFileSystem> *fs in self.fileSystems) {
+            if ([fs.name isEqualToString:fsName]) {
+                return fs;
+            }
+        }
+    }
+    return nil;
+
+}
+
+- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL {
+    if (localURL.fileSystemName == nil) return nil;
+    @try {
+        return [self fileSystemByName:localURL.fileSystemName];
+    }
+    @catch (NSException *e) {
+        return nil;
+    }
+}
+
 - (id)initWithWebView:(UIWebView*)theWebView
 {
     self = (CDVFile*)[super initWithWebView:theWebView];
     if (self) {
         filePlugin = self;
+//        @throw (@"Error!");
         [NSURLProtocol registerClass:[CDVFilesystemURLProtocol class]];
 
         fileSystems_ = [[NSMutableArray alloc] initWithCapacity:3];
@@ -175,26 +204,19 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
         paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);
         self.appDocsPath = [paths objectAtIndex:0];
 
-        [fileSystems_ addObject:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:[paths
objectAtIndex:0]]];
+        [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:[paths
objectAtIndex:0]]];
 
         self.persistentPath = [NSString stringWithFormat:@"/%@", [self.appDocsPath lastPathComponent]];
         self.temporaryPath = [NSString stringWithFormat:@"/%@", [self.appTempPath lastPathComponent]];
         // NSLog(@"docs: %@ - temp: %@", self.appDocsPath, self.appTempPath);
+        
+        [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
+
     }
 
     return self;
 }
 
-- (NSObject<CDVFileSystem> *)filesystemForURL:(CDVFilesystemURL *)localURL {
-    if (localURL.fileSystemType == -1) return nil;
-    @try {
-        return [self.fileSystems objectAtIndex:localURL.fileSystemType];
-    }
-    @catch (NSException *e) {
-        return nil;
-    }
-}
-
 - (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath
 {
     CDVFilesystemURL *localURL = nil;
@@ -249,9 +271,9 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     int type = [strType intValue];
     CDVPluginResult* result = nil;
 
-    if (type > 1) {
+    if (type > self.fileSystems.count) {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:NOT_FOUND_ERR];
-        NSLog(@"iOS only supports TEMPORARY and PERSISTENT file systems");
+        NSLog(@"No filesystem of type requested");
     } else {
         NSString* fullPath = @"/";
         // check for avail space for size request
@@ -260,11 +282,17 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
         if (pNumAvail && ([pNumAvail unsignedLongLongValue] < size)) {
             result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:QUOTA_EXCEEDED_ERR];
         } else {
-            NSMutableDictionary* fileSystem = [NSMutableDictionary dictionaryWithCapacity:2];
-            [fileSystem setObject:(type == TEMPORARY ? kW3FileTemporary : kW3FilePersistent)
forKey:@"name"];
-            NSDictionary* dirEntry = [self makeEntryForPath:fullPath fileSystem:type isDirectory:YES];
-            [fileSystem setObject:dirEntry forKey:@"root"];
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileSystem];
+            NSObject<CDVFileSystem> *rootFs = [self.fileSystems objectAtIndex:type];
+            if (rootFs == nil) {
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:NOT_FOUND_ERR];
+                NSLog(@"No filesystem of type requested");
+            } else {
+                NSMutableDictionary* fileSystem = [NSMutableDictionary dictionaryWithCapacity:2];
+                [fileSystem setObject:rootFs.name forKey:@"name"];
+                NSDictionary* dirEntry = [self makeEntryForPath:fullPath fileSystemName:rootFs.name
isDirectory:YES];
+                [fileSystem setObject:dirEntry forKey:@"root"];
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileSystem];
+            }
         }
     }
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -282,10 +310,10 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
  *		bool as NSNumber isFile
  *		NSString*  name - last part of path
  *		NSString* fullPath
- *		filesystem = FileSystem type -- actual filesystem will be created on the JS side if necessary,
to avoid
+ *		NSString* filesystemName - FileSystem name -- actual filesystem will be created on the
JS side if necessary, to avoid
  *         creating circular reference (FileSystem contains DirectoryEntry which contains
FileSystem.....!!)
  */
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir
 {
     NSMutableDictionary* dirEntry = [NSMutableDictionary dictionaryWithCapacity:5];
     NSString* lastPart = [fullPath lastPathComponent];
@@ -296,15 +324,15 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     [dirEntry setObject:[NSNumber numberWithBool:isDir]  forKey:@"isDirectory"];
     [dirEntry setObject:fullPath forKey:@"fullPath"];
     [dirEntry setObject:lastPart forKey:@"name"];
-    [dirEntry setObject: [NSNumber numberWithInt:fsType] forKey: @"filesystem"];
-
+    [dirEntry setObject: [NSNumber numberWithInt:([fsName isEqualToString:@"temporary"] ?
0 : 1)] forKey: @"filesystem"];
+    [dirEntry setObject:fsName forKey: @"filesystemName"];
     return dirEntry;
 }
 
 - (NSDictionary *)makeEntryForURL:(NSURL *)URL
 {
     CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithURL:URL];
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:fsURL.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:fsURL];
     return [fs makeEntryForLocalURL:fsURL];
 }
 
@@ -341,10 +369,10 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     } else {
         inputURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
     }
-    if (inputURI != nil && inputURI.fileSystemType == -1) {
+    if (inputURI != nil && inputURI.fileSystemName == nil) {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:ENCODING_ERR];
     } else {
-        CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:inputURI.fileSystemType];
+        NSObject<CDVFileSystem> *fs = [self filesystemForURL:inputURI];
         result = [fs entryForLocalURI:inputURI];
     }
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -415,7 +443,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     NSString* requestedPath = [command.arguments objectAtIndex:1];
     NSDictionary* options = [command.arguments objectAtIndex:2 withDefault:nil];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:baseURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:baseURI];
     CDVPluginResult* result = [fs getFileForURL:baseURI requestedPath:requestedPath options:options];
 
 
@@ -436,7 +464,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     // arguments are URL encoded
     CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments
objectAtIndex:0]];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
     CDVPluginResult* result = [fs getParentForURL:localURI];
 
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -451,7 +479,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     // arguments
     NSString* localURIstr = [command.arguments objectAtIndex:0];
     CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
     [fs getMetadataForURL:localURI callback:^(CDVPluginResult* result) {
         [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
     }];
@@ -467,7 +495,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     // arguments
     CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments
objectAtIndex:0]];
     NSDictionary* options = [command.arguments objectAtIndex:1 withDefault:nil];
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
     CDVPluginResult* result = [fs setMetadataForURL:localURI withObject:options];
 
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -492,7 +520,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
         // error if try to remove top level (documents or tmp) dir
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NO_MODIFICATION_ALLOWED_ERR];
     } else {
-        CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+        NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
         result = [fs removeFileAtURL:localURI];
     }
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -516,7 +544,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
         // error if try to remove top level (documents or tmp) dir
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NO_MODIFICATION_ALLOWED_ERR];
     } else {
-        CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+        NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
         result = [fs recursiveRemoveFileAtURL:localURI];
     }
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -560,8 +588,8 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     CDVFilesystemURL* srcURL = [CDVFilesystemURL fileSystemURLWithString:srcURLstr];
     CDVFilesystemURL* destURL = [CDVFilesystemURL fileSystemURLWithString:destURLstr];
 
-    CDVLocalFilesystem *srcFs = [self.fileSystems objectAtIndex:srcURL.fileSystemType];
-    CDVLocalFilesystem *destFs = [self.fileSystems objectAtIndex:destURL.fileSystemType];
+    NSObject<CDVFileSystem> *srcFs = [self filesystemForURL:srcURL];
+    NSObject<CDVFileSystem> *destFs = [self filesystemForURL:destURL];
 
     // optional argument; use last component from srcFullPath if new name not provided
     NSString* newName = ([arguments count] > 2) ? [arguments objectAtIndex:2] : [srcURL.url
lastPathComponent];
@@ -583,7 +611,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     // arguments
     NSString* localURIstr = [command.arguments objectAtIndex:0];
     CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
     [fs getFileMetadataForURL:localURI callback:^(CDVPluginResult* result) {
         [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -593,7 +621,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 - (void)readEntries:(CDVInvokedUrlCommand*)command
 {
     CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments
objectAtIndex:0]];
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
     CDVPluginResult *result = [fs readEntriesAtURL:localURI];
 
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -615,7 +643,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     NSInteger start = [[command argumentAtIndex:2] integerValue];
     NSInteger end = [[command argumentAtIndex:3] integerValue];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
     // TODO: implement
     if ([@"UTF-8" caseInsensitiveCompare : encoding] != NSOrderedSame) {
@@ -663,7 +691,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     NSInteger start = [[command argumentAtIndex:1] integerValue];
     NSInteger end = [[command argumentAtIndex:2] integerValue];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
     [self.commandDelegate runInBackground:^ {
         [fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString*
mimeType, CDVFileError errorCode) {
@@ -695,7 +723,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     NSInteger start = [[command argumentAtIndex:1] integerValue];
     NSInteger end = [[command argumentAtIndex:2] integerValue];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
     [self.commandDelegate runInBackground:^ {
         [fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString*
mimeType, CDVFileError errorCode) {
@@ -717,7 +745,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     NSInteger start = [[command argumentAtIndex:1] integerValue];
     NSInteger end = [[command argumentAtIndex:2] integerValue];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
     [self.commandDelegate runInBackground:^ {
         [fs readFileAtURL:localURI start:start end:end callback:^(NSData* data, NSString*
mimeType, CDVFileError errorCode) {
@@ -742,7 +770,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     CDVFilesystemURL* localURI = [CDVFilesystemURL fileSystemURLWithString:[command argumentAtIndex:0]];
     unsigned long long pos = (unsigned long long)[[command.arguments objectAtIndex:1] longLongValue];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
     CDVPluginResult *result = [fs truncateFileAtURL:localURI atPosition:pos];
 
     [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
@@ -766,7 +794,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     id argData = [arguments objectAtIndex:1];
     unsigned long long pos = (unsigned long long)[[arguments objectAtIndex:2] longLongValue];
 
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURI.fileSystemType];
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
 
 
     [fs truncateFileAtURL:localURI atPosition:pos];
@@ -841,7 +869,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 - (NSDictionary *)getDirectoryEntry:(NSString *)localPath isDirectory:(BOOL)bDirRequest
 {
     CDVFilesystemURL *localURL = [self fileSystemURLforLocalPath:localPath];
-    return [self makeEntryForPath:localURL.fullPath fileSystem:localURL.fileSystemType isDirectory:bDirRequest];
+    return [self makeEntryForPath:localURL.fullPath fileSystemName:localURL.fileSystemName
isDirectory:bDirRequest];
 }
 
 #pragma mark Internal methods for testing
@@ -849,9 +877,12 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 // [Currently used for testing file-transfer]
 - (NSString *)_filesystemPathForURL:(CDVFilesystemURL *)localURL
 {
-    CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:localURL.fileSystemType];
-    if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
-       return [fs filesystemPathForURL:localURL];
+    for (NSObject<CDVFileSystem> *fs in self.fileSystems) {
+        if ([fs.name isEqualToString:localURL.fileSystemName]) {
+            if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
+                return [fs filesystemPathForURL:localURL];
+            }
+        }
     }
     return nil;
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVLocalFilesystem.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.h b/src/ios/CDVLocalFilesystem.h
index 65c9269..a0186c8 100644
--- a/src/ios/CDVLocalFilesystem.h
+++ b/src/ios/CDVLocalFilesystem.h
@@ -27,7 +27,6 @@
 - (id) initWithName:(NSString *)name root:(NSString *)fsRoot;
 + (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
 
-@property (nonatomic,strong) NSString *name;
 @property (nonatomic,strong) NSString *fsRoot;
 
 @end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/590b9303/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 5ad2200..3e054c8 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -61,12 +61,12 @@
     // see if exists and is file or dir
     BOOL bExists = [fileMgr fileExistsAtPath:path isDirectory:&isDir];
     if (bExists) {
-        return [self makeEntryForPath:url.fullPath fileSystem:url.fileSystemType isDirectory:isDir];
+        return [self makeEntryForPath:url.fullPath fileSystemName:url.fileSystemName isDirectory:isDir];
     } else {
         return nil;
     }
 }
-- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystem:(int)fsType isDirectory:(BOOL)isDir
+- (NSDictionary*)makeEntryForPath:(NSString*)fullPath fileSystemName:(NSString *)fsName isDirectory:(BOOL)isDir
 {
     NSMutableDictionary* dirEntry = [NSMutableDictionary dictionaryWithCapacity:5];
     NSString* lastPart = [fullPath lastPathComponent];
@@ -77,7 +77,8 @@
     [dirEntry setObject:[NSNumber numberWithBool:isDir]  forKey:@"isDirectory"];
     [dirEntry setObject:fullPath forKey:@"fullPath"];
     [dirEntry setObject:lastPart forKey:@"name"];
-    [dirEntry setObject: [NSNumber numberWithInt:fsType] forKey: @"filesystem"];
+    [dirEntry setObject: [NSNumber numberWithInt:([fsName isEqualToString:@"temporary"] ?
0 : 1)] forKey: @"filesystem"];
+    [dirEntry setObject:fsName forKey: @"filesystemName"];
 
     return dirEntry;
 }
@@ -173,7 +174,7 @@
             } else {
                 // NSLog(@"newly created file/dir (%@) exists: %d", reqFullPath, [fileMgr
fileExistsAtPath:reqFullPath]);
                 // file existed or was created
-                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self
makeEntryForPath:requestedURL.fullPath fileSystem:baseURI.fileSystemType isDirectory:bDirRequest]];
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self
makeEntryForPath:requestedURL.fullPath fileSystemName:baseURI.fileSystemName isDirectory:bDirRequest]];
             }
         } // are all possible conditions met?
     }
@@ -200,7 +201,7 @@
     BOOL bIsDir;
     BOOL bExists = [fileMgr fileExistsAtPath:[self filesystemPathForURL:newURI] isDirectory:&bIsDir];
     if (bExists) {
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self
makeEntryForPath:newURI.fullPath fileSystem:newURI.fileSystemType isDirectory:bIsDir]];
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self
makeEntryForPath:newURI.fullPath fileSystemName:newURI.fileSystemName isDirectory:bIsDir]];
     } else {
         // invalid path or file does not exist
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
@@ -367,7 +368,7 @@
                 NSString* entryPath = [fileSystemPath stringByAppendingPathComponent:name];
                 BOOL bIsDir = NO;
                 [fileMgr fileExistsAtPath:entryPath isDirectory:&bIsDir];
-                NSDictionary* entryDict = [self makeEntryForPath:[self fullPathForFileSystemPath:entryPath]
fileSystem:localURI.fileSystemType isDirectory:bIsDir];
+                NSDictionary* entryDict = [self makeEntryForPath:[self fullPathForFileSystemPath:entryPath]
fileSystemName:localURI.fileSystemName isDirectory:bIsDir];
                 [entries addObject:entryDict];
             }
         }
@@ -549,7 +550,7 @@
             }
             if (bSuccess) {
                 // should verify it is there and of the correct type???
-                NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystem:srcURL.fileSystemType
isDirectory:bSrcIsDir];  // should be the same type as source
+                NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystemName:srcURL.fileSystemName
isDirectory:bSrcIsDir];  // should be the same type as source
                 result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newEntry];
             } else {
                 if (error) {
@@ -571,7 +572,7 @@
                 BOOL bSuccess = [data writeToFile:newFileSystemPath atomically:YES];
                 if (bSuccess) {
                     // should verify it is there and of the correct type???
-                    NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystem:destURL.fileSystemType
isDirectory:NO];
+                    NSDictionary* newEntry = [self makeEntryForPath:newFullPath fileSystemName:destURL.fileSystemName
isDirectory:NO];
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:newEntry];
                 } else {
                     result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION
messageAsInt:ABORT_ERR];


Mime
View raw message