ios:Update fileSystemURLforLocalPath: to return the most match url.
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/22fef76d Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/22fef76d Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/22fef76d Branch: refs/heads/master Commit: 22fef76d50ace8f2bcb65b524e0c836799cb2cd5 Parents: d9fa9d8 Author: lmnbeyond <[email protected]> Authored: Tue Feb 25 13:48:38 2014 +0800 Committer: lmnbeyond <[email protected]> Committed: Tue Feb 25 13:48:38 2014 +0800 ---------------------------------------------------------------------- src/ios/CDVFile.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/22fef76d/src/ios/CDVFile.m ---------------------------------------------------------------------- diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m index c9817aa..0eca081 100644 --- a/src/ios/CDVFile.m +++ b/src/ios/CDVFile.m @@ -275,17 +275,22 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile"; - (CDVFilesystemURL *)fileSystemURLforLocalPath:(NSString *)localPath { CDVFilesystemURL *localURL = nil; - // Try all installed filesystems, in order. If any one supports mapping from - // path to URL, and returns a URL, then use it. + NSUInteger shortestFullPath = 0; + + // Try all installed filesystems, in order. Return the most match url. for (id object in self.fileSystems) { if ([object respondsToSelector:@selector(URLforFilesystemPath:)]) { - localURL = [object URLforFilesystemPath:localPath]; - } - if (localURL) { - return localURL; + CDVFilesystemURL *url = [object URLforFilesystemPath:localPath]; + if (url){ + // A shorter fullPath would imply that the filesystem is a better match for the local path + if (!localURL || ([[url fullPath] length] < shortestFullPath)) { + localURL = url; + shortestFullPath = [[url fullPath] length]; + } + } } } - return nil; + return localURL; } - (NSNumber*)checkFreeDiskSpace:(NSString*)appPath
