[File] Check requested size in requestFileSystem().
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 9 Nov 2015 07:40:42 +0000 (08:40 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 9 Nov 2015 07:49:27 +0000 (08:49 +0100)
[Verification] Code compiles, pass rate 83/140.

Change-Id: I4c69bd81ffcdd232b9be39bc68d7c08d7d41195f
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/file/js/requestFileSystem.js

index 460fdd7..ba185ca 100644 (file)
@@ -21,6 +21,7 @@ cordova.define('cordova-plugin-file.tizen.requestFileSystem', function(require,
 module.exports = {
   requestFileSystem: function(successCallback, errorCallback, args) {
     var type = args[0];
+    var size = args[1];
     var fsName;
 
     switch(type) {
@@ -38,17 +39,42 @@ module.exports = {
         return;
     }
 
-    rootsUtils.getRoots(function(roots) {
-      for (var i = 0; i < roots.length; ++i) {
-        if (fsName === roots[i].filesystemName) {
-          successCallback({ 'name': fsName, 'root': roots[i] });
-          return;
-        }
-      }
+    try {
+      tizen.systeminfo.getPropertyValue('STORAGE', function (r) {
+          for (var i = 0; i < r.units.length; ++i) {
+            // both filesystems are located on internal storage
+            if ('INTERNAL' === r.units[i].type) {
+              if (size < r.units[i].availableCapacity) {
+                rootsUtils.getRoots(function(roots) {
+                  for (var i = 0; i < roots.length; ++i) {
+                    if (fsName === roots[i].filesystemName) {
+                      successCallback({ 'name': fsName, 'root': roots[i] });
+                      return;
+                    }
+                  }
+
+                  console.error('Filesystem not found: ' + fsName);
+                  errorCallback && errorCallback(FileError.NOT_FOUND_ERR);
+                });
+              } else {
+                console.error('Quote exceeded, requested: ' + size + ', available: ' + r.units[i].availableCapacity);
+                errorCallback && errorCallback(FileError.QUOTA_EXCEEDED_ERR);
+              }
+              return;
+            }
+          }
 
-      console.error('Filesystem not found: ' + fsName);
+          console.error('Internal storage not found');
+          errorCallback && errorCallback(FileError.NOT_FOUND_ERR);
+        }, function(e) {
+          console.error('Failed to get storage info: ' + fsName);
+          errorCallback && errorCallback(FileError.NOT_FOUND_ERR);
+        }
+      );
+    } catch (e) {
+      console.error('Exception: ' + e);
       errorCallback && errorCallback(FileError.NOT_FOUND_ERR);
-    });
+    }
   }
 };