You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/06/11 19:40:51 UTC

[1/3] git commit: CB-6922: Use getFileMetadata consistently to get metadata

Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 429d0720a -> 17297e56d


CB-6922: Use getFileMetadata consistently to get metadata


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/71ff2e47
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/71ff2e47
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/71ff2e47

Branch: refs/heads/master
Commit: 71ff2e47aa8999c74ba45140bfada8d520246b1e
Parents: 429d072
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jun 11 13:33:41 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 11 13:34:40 2014 -0400

----------------------------------------------------------------------
 src/ios/CDVLocalFilesystem.m | 56 ++++++++++++++++++++++++++-------------
 www/Entry.js                 |  7 +++--
 2 files changed, 42 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/71ff2e47/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index e665b04..861ce6f 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -707,26 +707,44 @@
 - (void)getFileMetadataForURL:(CDVFilesystemURL *)localURL callback:(void (^)(CDVPluginResult *))callback
 {
     NSString *path = [self filesystemPathForURL:localURL];
-        NSFileManager* fileMgr = [[NSFileManager alloc] init];
-        BOOL bIsDir = NO;
-        // make sure it exists and is not a directory
-        BOOL bExists = [fileMgr fileExistsAtPath:path isDirectory:&bIsDir];
-        if (!bExists || bIsDir) {
-            callback([CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR]);
-        } else {
-            // create dictionary of file info
-            NSError* __autoreleasing error = nil;
-            NSDictionary* fileAttrs = [fileMgr attributesOfItemAtPath:path error:&error];
-            NSMutableDictionary* fileInfo = [NSMutableDictionary dictionaryWithCapacity:5];
-            [fileInfo setObject:[NSNumber numberWithUnsignedLongLong:[fileAttrs fileSize]] forKey:@"size"];
-            [fileInfo setObject:localURL.fullPath forKey:@"fullPath"];
-            [fileInfo setObject:@"" forKey:@"type"];  // can't easily get the mimetype unless create URL, send request and read response so skipping
-            [fileInfo setObject:[path lastPathComponent] forKey:@"name"];
-            NSDate* modDate = [fileAttrs fileModificationDate];
-            NSNumber* msDate = [NSNumber numberWithDouble:[modDate timeIntervalSince1970] * 1000];
-            [fileInfo setObject:msDate forKey:@"lastModifiedDate"];
-            callback([CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileInfo]);
+    CDVPluginResult *result;
+    NSFileManager* fileMgr = [[NSFileManager alloc] init];
+
+    NSError* __autoreleasing error = nil;
+    NSDictionary* fileAttrs = [fileMgr attributesOfItemAtPath:path error:&error];
+
+    if (fileAttrs) {
+
+        // create dictionary of file info
+        NSMutableDictionary* fileInfo = [NSMutableDictionary dictionaryWithCapacity:5];
+
+        [fileInfo setObject:localURL.fullPath forKey:@"fullPath"];
+        [fileInfo setObject:@"" forKey:@"type"];  // can't easily get the mimetype unless create URL, send request and read response so skipping
+        [fileInfo setObject:[path lastPathComponent] forKey:@"name"];
+
+        // Ensure that directories (and other non-regular files) report size of 0
+        unsigned long long size = ([fileAttrs fileType] == NSFileTypeRegular ? [fileAttrs fileSize] : 0);
+        [fileInfo setObject:[NSNumber numberWithUnsignedLongLong:size] forKey:@"size"];
+
+        NSDate* modDate = [fileAttrs fileModificationDate];
+        if (modDate) {
+            [fileInfo setObject:[NSNumber numberWithDouble:[modDate timeIntervalSince1970] * 1000] forKey:@"lastModifiedDate"];
         }
+
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:fileInfo];
+
+    } else {
+        // didn't get fileAttribs
+        CDVFileError errorCode = ABORT_ERR;
+        NSLog(@"error getting metadata: %@", [error localizedDescription]);
+        if ([error code] == NSFileNoSuchFileError || [error code] == NSFileReadNoSuchFileError) {
+            errorCode = NOT_FOUND_ERR;
+        }
+        // log [NSNumber numberWithDouble: theMessage] objCtype to see what it returns
+        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errorCode];
+    }
+
+    callback(result);
 }
 
 @end

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/71ff2e47/www/Entry.js
----------------------------------------------------------------------
diff --git a/www/Entry.js b/www/Entry.js
index d143d32..956cbc4 100644
--- a/www/Entry.js
+++ b/www/Entry.js
@@ -65,13 +65,16 @@ function Entry(isFile, isDirectory, name, fullPath, fileSystem, nativeURL) {
 Entry.prototype.getMetadata = function(successCallback, errorCallback) {
     argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
     var success = successCallback && function(entryMetadata) {
-        var metadata = new Metadata(entryMetadata);
+        var metadata = new Metadata({
+            size: entryMetadata.size,
+            modificationTime: entryMetadata.lastModifiedDate
+        });
         successCallback(metadata);
     };
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(success, fail, "File", "getMetadata", [this.toInternalURL()]);
+    exec(success, fail, "File", "getFileMetadata", [this.toInternalURL()]);
 };
 
 /**


[2/3] git commit: CB-6922: Remove unused getMetadata native code

Posted by ia...@apache.org.
CB-6922: Remove unused getMetadata native code


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/090979e9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/090979e9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/090979e9

Branch: refs/heads/master
Commit: 090979e9d4dfcd2d696489033f28f31003f2b918
Parents: 71ff2e4
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jun 11 13:35:30 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 11 13:35:30 2014 -0400

----------------------------------------------------------------------
 src/android/FileUtils.java          |  2 +-
 src/ios/CDVAssetLibraryFilesystem.m | 31 ------------------------------
 src/ios/CDVFile.h                   |  6 ++----
 src/ios/CDVFile.m                   | 15 ---------------
 src/ios/CDVLocalFilesystem.m        | 33 --------------------------------
 5 files changed, 3 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/090979e9/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 9233a62..3f1c817 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -369,7 +369,7 @@ public class FileUtils extends CordovaPlugin {
                 }
             },callbackContext);
         }
-        else if (action.equals("getMetadata") || action.equals("getFileMetadata")) {
+        else if (action.equals("getFileMetadata")) {
             final String fname=args.getString(0);
             threadhelper( new FileOp( ){
                 public void run() throws FileNotFoundException, JSONException, MalformedURLException {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/090979e9/src/ios/CDVAssetLibraryFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVAssetLibraryFilesystem.m b/src/ios/CDVAssetLibraryFilesystem.m
index 965251a..1197f06 100644
--- a/src/ios/CDVAssetLibraryFilesystem.m
+++ b/src/ios/CDVAssetLibraryFilesystem.m
@@ -124,37 +124,6 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
     return [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_READABLE_ERR];
 }
 
-- (void)getMetadataForURL:(CDVFilesystemURL *)url callback:(void (^)(CDVPluginResult *))callback
-{
-    __block CDVPluginResult* result = nil;
-
-    // In this case, we need to use an asynchronous method to retrieve the file.
-    // Because of this, we can't just assign to `result` and send it at the end of the method.
-    // Instead, we return after calling the asynchronous method and send `result` in each of the blocks.
-    ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset* asset) {
-        if (asset) {
-            // We have the asset!  Retrieve the metadata and send it off.
-            NSDate* date = [asset valueForProperty:ALAssetPropertyDate];
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[date timeIntervalSince1970] * 1000];
-            callback(result);
-        } else {
-            // We couldn't find the asset.  Send the appropriate error.
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsInt:NOT_FOUND_ERR];
-            callback(result);
-        }
-    };
-    // TODO(maxw): Consider making this a class variable since it's the same every time.
-    ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError* error) {
-        // Retrieving the asset failed for some reason.  Send the appropriate error.
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[error localizedDescription]];
-        callback(result);
-    };
-
-    ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
-    [assetsLibrary assetForURL:[self assetLibraryURLForLocalURL:url] resultBlock:resultBlock failureBlock:failureBlock];
-    return;
-}
-
 - (CDVPluginResult*)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options
 {
     // setMetadata doesn't make sense for asset library files

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/090979e9/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index c37fb44..74c0146 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -65,9 +65,8 @@ typedef int CDVFileError;
 @protocol CDVFileSystem
 - (CDVPluginResult *)entryForLocalURI:(CDVFilesystemURL *)url;
 - (CDVPluginResult *)getFileForURL:(CDVFilesystemURL *)baseURI requestedPath:(NSString *)requestedPath options:(NSDictionary *)options;
-- (CDVPluginResult*)getParentForURL:(CDVFilesystemURL *)localURI;
-- (void)getMetadataForURL:(CDVFilesystemURL *)url callback:(void (^)(CDVPluginResult *))callback;
-- (CDVPluginResult*)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options;
+- (CDVPluginResult *)getParentForURL:(CDVFilesystemURL *)localURI;
+- (CDVPluginResult *)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options;
 - (CDVPluginResult *)removeFileAtURL:(CDVFilesystemURL *)localURI;
 - (CDVPluginResult *)recursiveRemoveFileAtURL:(CDVFilesystemURL *)localURI;
 - (CDVPluginResult *)readEntriesAtURL:(CDVFilesystemURL *)localURI;
@@ -115,7 +114,6 @@ typedef int CDVFileError;
 - (void)getDirectory:(CDVInvokedUrlCommand*)command;
 - (void)getFile:(CDVInvokedUrlCommand*)command;
 - (void)getParent:(CDVInvokedUrlCommand*)command;
-- (void)getMetadata:(CDVInvokedUrlCommand*)command;
 - (void)removeRecursively:(CDVInvokedUrlCommand*)command;
 - (void)remove:(CDVInvokedUrlCommand*)command;
 - (void)copyTo:(CDVInvokedUrlCommand*)command;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/090979e9/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index dd6bfd3..0975340 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -646,21 +646,6 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 }
 
 /*
- * get MetaData of entry
- * Currently MetaData only includes modificationTime.
- */
-- (void)getMetadata:(CDVInvokedUrlCommand*)command
-{
-    // arguments
-    CDVFilesystemURL* localURI = [self fileSystemURLforArg:command.arguments[0]];
-    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURI];
-    [fs getMetadataForURL:localURI callback:^(CDVPluginResult* result) {
-        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
-    }];
-
-}
-
-/*
  * set MetaData of entry
  * Currently we only support "com.apple.MobileBackup" (boolean)
  */

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/090979e9/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 861ce6f..d1576ad 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -262,39 +262,6 @@
     return result;
 }
 
-- (void)getMetadataForURL:(CDVFilesystemURL *)url callback:(void (^)(CDVPluginResult *))callback
-{
-
-    NSFileManager* fileMgr = [[NSFileManager alloc] init];
-    NSError* __autoreleasing error = nil;
-
-    CDVPluginResult *result;
-    NSDictionary* fileAttribs = [fileMgr attributesOfItemAtPath:[self  filesystemPathForURL:url] error:&error];
-
-    if (fileAttribs) {
-        // Ensure that directories (and other non-regular files) report size of 0
-        unsigned long long size = ([fileAttribs fileType] == NSFileTypeRegular ? [fileAttribs fileSize] : 0);
-        NSDate* modDate = [fileAttribs fileModificationDate];
-        if (modDate) {
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"modificationTime": @([modDate timeIntervalSince1970] * 1000), @"size": @(size)}];
-        }
-    } else {
-        // didn't get fileAttribs
-        CDVFileError errorCode = ABORT_ERR;
-        NSLog(@"error getting metadata: %@", [error localizedDescription]);
-        if ([error code] == NSFileNoSuchFileError) {
-            errorCode = NOT_FOUND_ERR;
-        }
-        // log [NSNumber numberWithDouble: theMessage] objCtype to see what it returns
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:errorCode];
-    }
-    if (!result) {
-        // invalid path or file does not exist
-        result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION];
-    }
-    callback(result);
-}
-
 - (CDVPluginResult*)setMetadataForURL:(CDVFilesystemURL *)localURI withObject:(NSDictionary *)options
 {
     BOOL ok = NO;


[3/3] git commit: CB-6902: Use File.lastModified rather than .lastModifiedDate

Posted by ia...@apache.org.
CB-6902: Use File.lastModified rather than .lastModifiedDate


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/17297e56
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/17297e56
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/17297e56

Branch: refs/heads/master
Commit: 17297e56d15001d168fbe0a5e700366123687b6f
Parents: 090979e
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Jun 11 13:37:43 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Jun 11 13:37:43 2014 -0400

----------------------------------------------------------------------
 www/File.js | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/17297e56/www/File.js
----------------------------------------------------------------------
diff --git a/www/File.js b/www/File.js
index d080315..82ff7a7 100644
--- a/www/File.js
+++ b/www/File.js
@@ -32,6 +32,8 @@ var File = function(name, localURL, type, lastModifiedDate, size){
     this.name = name || '';
     this.localURL = localURL || null;
     this.type = type || null;
+    this.lastModified = lastModifiedDate || null;
+    // For backwards compatibility, store the timestamp in lastModifiedDate as well
     this.lastModifiedDate = lastModifiedDate || null;
     this.size = size || 0;
 
@@ -67,7 +69,7 @@ File.prototype.slice = function(start, end) {
         }
     }
 
-    var newFile = new File(this.name, this.localURL, this.type, this.lastModifiedDate, this.size);
+    var newFile = new File(this.name, this.localURL, this.type, this.lastModified, this.size);
     newFile.start = this.start + newStart;
     newFile.end = this.start + newEnd;
     return newFile;