cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [01/40] git commit: CB-5959: Android, iOS: Return size with Entry.getMetadata() method
Date Fri, 28 Feb 2014 21:35:38 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 6a3bc14a3 -> 21e119692


CB-5959: Android, iOS: Return size with Entry.getMetadata() method


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

Branch: refs/heads/master
Commit: 9ac8e477c0fda6aed3878a4cf165257f00e1bf83
Parents: 3c0ba72
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Feb 7 10:06:15 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Feb 7 10:34:49 2014 -0500

----------------------------------------------------------------------
 src/android/FileUtils.java   | 13 ++-----------
 src/ios/CDVLocalFilesystem.m |  4 +++-
 www/Entry.js                 |  4 ++--
 www/Metadata.js              | 13 +++++++++++--
 4 files changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ac8e477/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 23496ca..6acc101 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -314,23 +314,14 @@ public class FileUtils extends CordovaPlugin {
                 }
             },callbackContext);
         }
-        else if (action.equals("getMetadata")) {
-            final String fname=args.getString(0);
-            threadhelper( new FileOp( ){
-                public void run() throws FileNotFoundException, JSONException, MalformedURLException
{
-                    JSONObject obj = getFileMetadata(fname);
-                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,
obj.getLong("lastModifiedDate")));
-                }
-            }, callbackContext);
-        }
-        else if (action.equals("getFileMetadata")) {
+        else if (action.equals("getMetadata") || action.equals("getFileMetadata")) {
             final String fname=args.getString(0);
             threadhelper( new FileOp( ){
                 public void run() throws FileNotFoundException, JSONException, MalformedURLException
{
                     JSONObject obj = getFileMetadata(fname);
                     callbackContext.success(obj);
                 }
-            },callbackContext);
+            }, callbackContext);
         }
         else if (action.equals("getParent")) {
             final String fname=args.getString(0);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ac8e477/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index f16470f..f80d1fa 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -257,9 +257,11 @@
     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 messageAsDouble:[modDate
timeIntervalSince1970] * 1000];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"modificationTime":
@([modDate timeIntervalSince1970] * 1000), @"size": @(size)}];
         }
     } else {
         // didn't get fileAttribs

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ac8e477/www/Entry.js
----------------------------------------------------------------------
diff --git a/www/Entry.js b/www/Entry.js
index 223e2bc..6f6ad61 100644
--- a/www/Entry.js
+++ b/www/Entry.js
@@ -59,8 +59,8 @@ function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
  */
 Entry.prototype.getMetadata = function(successCallback, errorCallback) {
     argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
-    var success = successCallback && function(lastModified) {
-        var metadata = new Metadata(lastModified);
+    var success = successCallback && function(entryMetadata) {
+        var metadata = new Metadata(entryMetadata);
         successCallback(metadata);
     };
     var fail = errorCallback && function(code) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/9ac8e477/www/Metadata.js
----------------------------------------------------------------------
diff --git a/www/Metadata.js b/www/Metadata.js
index bee26bd..dadae7e 100644
--- a/www/Metadata.js
+++ b/www/Metadata.js
@@ -24,8 +24,17 @@
  *
  * {Date} modificationTime (readonly)
  */
-var Metadata = function(time) {
-    this.modificationTime = (typeof time != 'undefined'?new Date(time):null);
+var Metadata = function(metadata) {
+    if (typeof metadata == "object") {
+        this.modificationTime = new Date(metadata.modificationTime);
+        this.size = +(metadata.size);
+    } else if (typeof metadata == "undefined") {
+        this.modificationTime = null;
+        this.size = null;
+    } else {
+        /* Backwards compatiblity with platforms that only return a timestamp */
+        this.modificationTime = new Date(metadata);
+    }
 };
 
 module.exports = Metadata;


Mime
View raw message