[File] Code structure changed to match cordova architecture.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 8 Apr 2016 08:34:50 +0000 (10:34 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 8 Apr 2016 08:34:50 +0000 (10:34 +0200)
Change-Id: I12878d562c57285b483dbcee02a7191fbb105f9c
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
17 files changed:
src/cordova/cordova_api.js
src/file/cordova_file_api.js
src/lib/cordova-5.1.1.js
src/lib/cordova_plugins.js
src/lib/plugins/cordova-plugin-file/tizen/DirectoryEntry.js [moved from src/file/js/DirectoryEntry.js with 87% similarity]
src/lib/plugins/cordova-plugin-file/tizen/DirectoryReader.js [moved from src/file/js/DirectoryReader.js with 81% similarity]
src/lib/plugins/cordova-plugin-file/tizen/Entry.js [moved from src/file/js/Entry.js with 80% similarity]
src/lib/plugins/cordova-plugin-file/tizen/Errors.js [moved from src/file/js/Errors.js with 75% similarity]
src/lib/plugins/cordova-plugin-file/tizen/File.js [moved from src/file/js/File.js with 85% similarity]
src/lib/plugins/cordova-plugin-file/tizen/FileReader.js [moved from src/file/js/FileReader.js with 92% similarity]
src/lib/plugins/cordova-plugin-file/tizen/FileSystem.js [moved from src/file/js/FileSystem.js with 100% similarity]
src/lib/plugins/cordova-plugin-file/tizen/FileWriter.js [moved from src/file/js/FileWriter.js with 84% similarity]
src/lib/plugins/cordova-plugin-file/tizen/fileSystemPaths.js [moved from src/file/js/fileSystemPaths.js with 100% similarity]
src/lib/plugins/cordova-plugin-file/tizen/fileSystems-roots.js [moved from src/file/js/fileSystems-roots.js with 89% similarity]
src/lib/plugins/cordova-plugin-file/tizen/requestFileSystem.js [moved from src/file/js/requestFileSystem.js with 96% similarity]
src/lib/plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js [moved from src/file/js/resolveLocalFileSystemURI.js with 79% similarity]
src/lib/plugins/cordova-plugin-file/tizen/rootUtils.js [moved from src/file/js/rootsUtils.js with 94% similarity]

index 516c2bc..92438ce 100755 (executable)
@@ -52,8 +52,5 @@ exports = {
         }
       }
     });
-
-    // load file native plugin
-    tizen.cordova.file(require);
   }
 };
index b5a171d..a87e834 100755 (executable)
  *    limitations under the License.
  */
 
-//= require('Errors.js');
-//= require('rootsUtils.js');
-//= require('DirectoryEntry.js');
-//= require('DirectoryReader.js');
-//= require('Entry.js');
-//= require('FileReader.js');
-//= require('fileSystemPaths.js');
-//= require('fileSystems-roots.js');
-//= require('FileWriter.js');
-//= require('requestFileSystem.js');
-//= require('resolveLocalFileSystemURI.js');
+var native_ = new xwalk.utils.NativeManager(extension);
 
-//= require('FileSystem.js');
-//= require('File.js');
+function FileManager() {}
+
+FileManager.prototype.truncate = function(uri, length, successCallback, errorCallback) {
+  var callArgs = {
+    'uri': uri,
+    'length': length
+  };
+
+  var result = native_.callSync('File_truncate', callArgs);
+  if (native_.isFailure(result)) {
+    if (errorCallback) {
+      errorCallback(native_.getErrorObject(result));
+    }
+  } else {
+    if (successCallback) {
+      successCallback(length);
+    }
+  }
+};
+
+exports = new FileManager();
index b6b1965..cb58c1d 100644 (file)
@@ -1334,8 +1334,6 @@ module.exports = {
 
      modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
 
-     tizen.cordova.load(require);
-
      channel.onNativeReady.fire();
 
  // End of bootstrap
index 443c37f..00817ca 100644 (file)
@@ -206,6 +206,73 @@ module.exports = [
         "runs": true
     },
     {
+      "file": "plugins/cordova-plugin-file/tizen/Errors.js",
+      "id": "cordova-plugin-file.tizen.Errors",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/rootUtils.js",
+      "id": "cordova-plugin-file.tizen.rootUtils",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/DirectoryEntry.js",
+      "id": "cordova-plugin-file.tizen.DirectoryEntry",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/DirectoryReader.js",
+      "id": "cordova-plugin-file.tizen.DirectoryReader",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/Entry.js",
+      "id": "cordova-plugin-file.tizen.Entry",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/FileReader.js",
+      "id": "cordova-plugin-file.tizen.FileReader",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/fileSystemPaths.js",
+      "id": "cordova-plugin-file.tizen.fileSystemPaths",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/fileSystems-roots.js",
+      "id": "cordova-plugin-file.tizen.fileSystems-roots",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/FileWriter.js",
+      "id": "cordova-plugin-file.tizen.FileWriter",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/requestFileSystem.js",
+      "id": "cordova-plugin-file.tizen.requestFileSystem",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js",
+      "id": "cordova-plugin-file.tizen.resolveLocalFileSystemURI",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/File.js",
+      "id": "cordova-plugin-file.tizen.File",
+      "runs": true
+    },
+    {
+      "file": "plugins/cordova-plugin-file/tizen/FileSystem.js",
+      "id": "cordova-plugin-file.tizen.FileSystem",
+      "merges": [
+        "window.FileSystem"
+      ]
+    },
+    {
         "file": "plugins/cordova-plugin-file-transfer/www/FileTransferError.js",
         "id": "cordova-plugin-file-transfer.FileTransferError",
         "clobbers": [
similarity index 87%
rename from src/file/js/DirectoryEntry.js
rename to src/lib/plugins/cordova-plugin-file/tizen/DirectoryEntry.js
index 3f11fd4..4349e33 100644 (file)
@@ -18,6 +18,9 @@
 cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exports, module) {
 // TODO: remove -> end
 
+  var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+  var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
   function sanitizePath(path) {
     var prepend = '/' === path[0];
     var input = path.split('/');
@@ -46,8 +49,8 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
   }
 
   var getFunction = function(successCallback, errorCallback, args, isDirectory) {
-    var uri = rootsUtils.internalUrlToNativePath(args[0]),
-        path = rootsUtils.stripTrailingSlash(args[1]),
+    var uri = rootUtils.internalUrlToNativePath(args[0]),
+        path = rootUtils.stripTrailingSlash(args[1]),
         options = args[2] || {},
         create_flag = !!options.create,
         exclusive_flag = !!options.exclusive,
@@ -74,7 +77,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
       absolute_path = uri + '/' + path;
     }
 
-    var root = rootsUtils.findFilesystem(absolute_path).nativeURL;
+    var root = rootUtils.findFilesystem(absolute_path).nativeURL;
     var clean_path = sanitizePath(absolute_path);
 
     if (0 !== clean_path.indexOf(root)) {
@@ -86,7 +89,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
     var parent_path = clean_path.substring(0, clean_path.lastIndexOf('/'));
     var child_name = clean_path.substring(clean_path.lastIndexOf('/') + 1);
 
-    if (!rootsUtils.isValidFileName(child_name)) {
+    if (!rootUtils.isValidFileName(child_name)) {
       console.error('Disallowed character detected in file name: ' + child_name);
       errorCallback && errorCallback(FileError.ENCODING_ERR);
       return;
@@ -101,7 +104,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
         console.error('Error while resolving dir - already exist file');
         errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR);
       } else {
-        successCallback && successCallback(rootsUtils.createEntry(dir));
+        successCallback && successCallback(rootUtils.createEntry(dir));
       }
     };
 
@@ -120,7 +123,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
                   new_obj = dir.createFile(child_name);
                 }
 
-                successCallback && successCallback(rootsUtils.createEntry(new_obj));
+                successCallback && successCallback(rootUtils.createEntry(new_obj));
               },
               function () {
                 console.error('Error -  immediate parent does not exist');
@@ -130,7 +133,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
           );
         } catch (err) {
           console.error('Error - Could not resolve');
-          errorCallback && errorCallback(ConvertTizenFileError(err));
+          errorCallback && errorCallback(convertTizenFileError(err));
         }
       } else {
         console.error('Error - create flag is false - new directory would not be created');
@@ -143,7 +146,7 @@ cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exp
       tizen.filesystem.resolve(clean_path, resolveSuccess, resolveError, 'rw');
     } catch (err) {
       console.error('Error - Could not resolve');
-      errorCallback && errorCallback(ConvertTizenFileError(err));
+      errorCallback && errorCallback(convertTizenFileError(err));
     }
   };
 
@@ -152,14 +155,14 @@ module.exports = {
     getFunction(successCallback, errorCallback, args, true);
   },
   removeRecursively: function(successCallback, errorCallback, args) {
-    var uri = rootsUtils.internalUrlToNativePath(args[0]);
+    var uri = rootUtils.internalUrlToNativePath(args[0]);
 
     if (!uri) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
       return;
     }
 
-    if (rootsUtils.isRootUri(uri)) {
+    if (rootUtils.isRootUri(uri)) {
       console.error('It is not allowed to remove root directory.');
       errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
       return;
@@ -189,16 +192,16 @@ module.exports = {
               }
             } catch (err) {
               console.error('Error - Could not deleteDirectory');
-              errorCallback && errorCallback(ConvertTizenFileError(err));
+              errorCallback && errorCallback(convertTizenFileError(err));
             }
           }, function(e) {
             console.error('Error: ' + e.message);
-            errorCallback && errorCallback(ConvertTizenFileError(e));
+            errorCallback && errorCallback(convertTizenFileError(e));
           }, 'rw'
       );
     } catch (err) {
       console.error('Error - Could not resolve');
-      errorCallback && errorCallback(ConvertTizenFileError(err));
+      errorCallback && errorCallback(convertTizenFileError(err));
     }
   },
   getFile: function(successCallback, errorCallback, args) {
 cordova.define('cordova-plugin-file.tizen.DirectoryReader', function(require, exports, module) {
 // TODO: remove -> end
 
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
 module.exports = {
   readEntries: function(successCallback, errorCallback, args) {
-    var uri = rootsUtils.internalUrlToNativePath(args[0]);
+    var uri = rootUtils.internalUrlToNativePath(args[0]);
 
     if (!uri) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
@@ -28,7 +31,7 @@ module.exports = {
     }
 
     var fail = function(e) {
-      errorCallback && errorCallback(ConvertTizenFileError(e));
+      errorCallback && errorCallback(convertTizenFileError(e));
     }
     try {
       tizen.filesystem.resolve(uri,
@@ -36,7 +39,7 @@ module.exports = {
           f.listFiles(function(v) {
             var retVal = [];
             for (var i = 0; i < v.length; ++i) {
-              var obj = rootsUtils.createEntry(v[i], rootsUtils.findFilesystem(v[i].toURI()).filesystemName);
+              var obj = rootUtils.createEntry(v[i], rootUtils.findFilesystem(v[i].toURI()).filesystemName);
               obj.isDirectory = v[i].isDirectory;
               obj.isFile = v[i].isFile;
               retVal.push(obj);
similarity index 80%
rename from src/file/js/Entry.js
rename to src/lib/plugins/cordova-plugin-file/tizen/Entry.js
index 1b258e8..a677fea 100644 (file)
@@ -18,6 +18,9 @@
 cordova.define('cordova-plugin-file.tizen.Entry', function(require, exports, module) {
 // TODO: remove -> end
 
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
 var resolveParent = function(srcURL, errorCallback, rest){
   try {
     tizen.filesystem.resolve(
@@ -32,19 +35,19 @@ var resolveParent = function(srcURL, errorCallback, rest){
           }
         }, function (err) {
           console.error('Error - resolve file ' + srcURL + ' failed');
-          errorCallback && errorCallback(ConvertTizenFileError(err));
+          errorCallback && errorCallback(convertTizenFileError(err));
         },
     'r');
   } catch (exception) {
     console.error('Error - resolve ' + srcURL + ' file thrown exception');
-    errorCallback && errorCallback(ConvertTizenFileError(exception));
+    errorCallback && errorCallback(convertTizenFileError(exception));
   }
 };
 
 var changeFile = function(method, successCallback, errorCallback, args) {
-  var srcURL = rootsUtils.internalUrlToNativePath(args[0]);
+  var srcURL = rootUtils.internalUrlToNativePath(args[0]);
   var name = args[2];
-  var destDir = rootsUtils.internalUrlToNativePath(args[1]);
+  var destDir = rootUtils.internalUrlToNativePath(args[1]);
   var destURL = destDir + '/' + name;
 
   function fail(e, msg) {
@@ -59,7 +62,7 @@ var changeFile = function(method, successCallback, errorCallback, args) {
     return;
   }
 
-  if (!rootsUtils.isValidFileName(name)) {
+  if (!rootUtils.isValidFileName(name)) {
     fail(FileError.ENCODING_ERR, 'Error - Disallowed character detected in the file name: ' + name);
     return;
   }
@@ -79,22 +82,22 @@ var changeFile = function(method, successCallback, errorCallback, args) {
               tizen.filesystem.resolve(
                 destURL,
                 function (destFile) {
-                  var destEntry = rootsUtils.createEntry(destFile);
+                  var destEntry = rootUtils.createEntry(destFile);
                   destEntry.isDirectory = destFile.isDirectory;
                   successCallback && successCallback(destEntry);
                 }, function (err) {
-                  fail(ConvertTizenFileError(err), 'Error - resolve result entry failed');
+                  fail(convertTizenFileError(err), 'Error - resolve result entry failed');
                 }
               );
             } catch (exception) {
-              fail(ConvertTizenFileError(exception), 'Error - resolve result entry thrown exception');
+              fail(convertTizenFileError(exception), 'Error - resolve result entry thrown exception');
             }
           }, function (err) {
-            fail(ConvertTizenFileError(err), 'Error - ' + method + ' operation failed');
+            fail(convertTizenFileError(err), 'Error - ' + method + ' operation failed');
           }
       );
     } catch (exception) {
-      fail(ConvertTizenFileError(exception), 'Error - ' + method + ' operation thrown exception');
+      fail(convertTizenFileError(exception), 'Error - ' + method + ' operation thrown exception');
     }
   }
 
@@ -117,7 +120,7 @@ var changeFile = function(method, successCallback, errorCallback, args) {
                 performAction(srcFile, parentDir);
               }, 'r');
             } catch (exception) {
-              fail(ConvertTizenFileError(exception), 'Error - resolve destination entry threw exception');
+              fail(convertTizenFileError(exception), 'Error - resolve destination entry threw exception');
             }
           }
       );
@@ -125,13 +128,13 @@ var changeFile = function(method, successCallback, errorCallback, args) {
       fail(FileError.NOT_FOUND_ERR, 'Error - destination directory does not exist');
     }, 'r');
   } catch (e) {
-    fail(ConvertTizenFileError(e), 'Error - resolve destination directory threw exception');
+    fail(convertTizenFileError(e), 'Error - resolve destination directory threw exception');
   }
 };
 
 module.exports = {
   getFileMetadata: function(successCallback, errorCallback, args) {
-    var uri = rootsUtils.internalUrlToNativePath(args[0]);
+    var uri = rootUtils.internalUrlToNativePath(args[0]);
     if (!uri) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
       return;
@@ -141,11 +144,11 @@ module.exports = {
         var result = { 'size': file.fileSize, 'lastModifiedDate': file.modified };
         successCallback && successCallback(result);
       }, function (err) {
-        errorCallback && errorCallback(ConvertTizenFileError(err));
+        errorCallback && errorCallback(convertTizenFileError(err));
       }, 'r');
     } catch (exception) {
       console.error('Error - resolve failed');
-      errorCallback && errorCallback(ConvertTizenFileError(exception));
+      errorCallback && errorCallback(convertTizenFileError(exception));
     }
   },
   setMetadata: function(successCallback, errorCallback, args) {
@@ -159,14 +162,14 @@ module.exports = {
     changeFile('copyTo', successCallback, errorCallback, args);
   },
   remove: function(successCallback, errorCallback, args) {
-    var url = rootsUtils.internalUrlToNativePath(args[0]);
+    var url = rootUtils.internalUrlToNativePath(args[0]);
 
     if (!url) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
       return;
     }
 
-    if (rootsUtils.isRootUri(url)) {
+    if (rootUtils.isRootUri(url)) {
       console.error('It is not allowed to remove root directory.');
       errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
       return;
@@ -180,7 +183,7 @@ module.exports = {
                       function() {successCallback && successCallback();},
                       function(err) {
                         console.error('Error - ' + method + ' failed');
-                        errorCallback && errorCallback(ConvertTizenFileError(err));
+                        errorCallback && errorCallback(convertTizenFileError(err));
                         }];
           if (srcFile.isFile) {
             //remove recursive flag
@@ -190,27 +193,27 @@ module.exports = {
             parentDir[method].apply(parentDir, args);
           } catch (exception) {
             console.error('Error - ' + method + ' thrown exception ' + JSON.stringify(exception));
-            errorCallback && errorCallback(ConvertTizenFileError(exception));
+            errorCallback && errorCallback(convertTizenFileError(exception));
           }
         }
     );
   },
   getParent: function(successCallback, errorCallback, args) {
-    var url = rootsUtils.internalUrlToNativePath(args[0]);
+    var url = rootUtils.internalUrlToNativePath(args[0]);
 
     if (!url) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
       return;
     }
 
-    if (rootsUtils.isRootUri(url)) {
-      successCallback && successCallback(rootsUtils.findFilesystem(url));
+    if (rootUtils.isRootUri(url)) {
+      successCallback && successCallback(rootUtils.findFilesystem(url));
       return;
     }
 
     resolveParent(url, errorCallback,
         function(srcFile, parentDir){
-          successCallback && successCallback(rootsUtils.createEntry(srcFile.parent));
+          successCallback && successCallback(rootUtils.createEntry(srcFile.parent));
         }
     );
   }
similarity index 75%
rename from src/file/js/Errors.js
rename to src/lib/plugins/cordova-plugin-file/tizen/Errors.js
index 89080f5..c31ff4c 100644 (file)
  *    limitations under the License.
  */
 
+// TODO: remove when added to public cordova repository -> begin
+cordova.define('cordova-plugin-file.tizen.Errors', function(require, exports, module) {
+// TODO: remove -> end
+
 /**
  * Function converting a Tizen error to a cordova error
  *
  * {unsigned short} WebAPIError error
  */
-function ConvertTizenFileError(err) {
+function convertTizenFileError(err) {
   switch (err.name) {
     case 'InvalidValuesError':
       return FileError.ENCODING_ERR;
@@ -34,3 +38,9 @@ function ConvertTizenFileError(err) {
       return FileError.ENCODING_ERR;
   }
 }
+
+module.exports = convertTizenFileError;
+
+//TODO: remove when added to public cordova repository -> begin
+});
+//TODO: remove -> end
similarity index 85%
rename from src/file/js/File.js
rename to src/lib/plugins/cordova-plugin-file/tizen/File.js
index fd6bcd1..35c2f6b 100644 (file)
@@ -48,9 +48,4 @@ console.log('Loaded cordova.file API');
 
 // TODO: remove when added to public cordova repository -> begin
 });
-
-exports = function(require) {
-  require('cordova-tizen').addPlugin('cordova-plugin-file.File', plugin_name, 'runs');
-  require('cordova-tizen').addPlugin('cordova-plugin-file.FileSystem', 'cordova-plugin-file.tizen.FileSystem', 'merges', 'window.FileSystem');
-};
 // TODO: remove -> end
similarity index 92%
rename from src/file/js/FileReader.js
rename to src/lib/plugins/cordova-plugin-file/tizen/FileReader.js
index d724459..b6c321c 100644 (file)
 cordova.define('cordova-plugin-file.tizen.FileReader', function(require, exports, module) {
 // TODO: remove -> end
 
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
 function read(operation, url, start, end, successCallback, errorCallback, encoding) {
-  url = rootsUtils.internalUrlToNativePath(url);
+  url = rootUtils.internalUrlToNativePath(url);
 
   if (!url) {
     errorCallback && errorCallback(FileError.ENCODING_ERR);
@@ -27,7 +30,7 @@ function read(operation, url, start, end, successCallback, errorCallback, encodi
   }
 
   var fail = function(e) {
-    errorCallback && errorCallback(ConvertTizenFileError(e));
+    errorCallback && errorCallback(convertTizenFileError(e));
   }
   var win = function(size) {
     successCallback && successCallback(size);
similarity index 84%
rename from src/file/js/FileWriter.js
rename to src/lib/plugins/cordova-plugin-file/tizen/FileWriter.js
index 9150723..e592166 100644 (file)
@@ -18,8 +18,8 @@
 cordova.define('cordova-plugin-file.tizen.FileWriter', function(require, exports, module) {
 // TODO: remove -> end
 
-var utils_ = xwalk.utils;
-var native_ = new utils_.NativeManager(extension);
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
 
 // https://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
 function toUTF8Array(str) {
@@ -55,7 +55,7 @@ function toUTF8Array(str) {
 
 module.exports = {
   write: function(successCallback, errorCallback, args) {
-    var uri = rootsUtils.internalUrlToNativePath(args[0]);
+    var uri = rootUtils.internalUrlToNativePath(args[0]);
     var data = args[1];
     var position = args[2];
     var isBinary = args[3];
@@ -110,34 +110,34 @@ module.exports = {
             successCallback && successCallback(length);
           }, errorCallback, [args[0], stream.position]);
         } catch (error) {
-          errorCallback && errorCallback(ConvertTizenFileError(error));
+          errorCallback && errorCallback(convertTizenFileError(error));
         }
       }
 
       var openStreamError = function (error) {
-        errorCallback && errorCallback(ConvertTizenFileError(error));
+        errorCallback && errorCallback(convertTizenFileError(error));
       }
 
       try {
         file.openStream('rw', openStreamSuccess, openStreamError);
       } catch (error) {
-        errorCallback && errorCallback(ConvertTizenFileError(error));
+        errorCallback && errorCallback(convertTizenFileError(error));
       }
     }
 
     var onError = function (error) {
-      errorCallback && errorCallback(ConvertTizenFileError(error));
+      errorCallback && errorCallback(convertTizenFileError(error));
     }
 
     try {
       tizen.filesystem.resolve(uri, onSuccess, onError, 'rw');
     } catch (error) {
-      errorCallback && errorCallback(ConvertTizenFileError(error));
+      errorCallback && errorCallback(convertTizenFileError(error));
     }
   },
 
   truncate: function(successCallback, errorCallback, args) {
-    var uri = rootsUtils.internalUrlToNativePath(args[0]);
+    var uri = rootUtils.internalUrlToNativePath(args[0]);
     var length = args[1];
 
     if (!uri) {
@@ -150,17 +150,11 @@ module.exports = {
       uri = uri.substring(uriPrefix.length);
     }
 
-    var callArgs = {
-      'uri': uri,
-      'length': length
-    };
-
-    var result = native_.callSync('File_truncate', callArgs);
-    if (native_.isFailure(result)) {
-      errorCallback && errorCallback(ConvertTizenFileError(native_.getErrorObject(result)));
-    } else {
-      successCallback && successCallback(length);
-    }
+    tizen.cordova.file.truncate(uri, length, successCallback, function(error) {
+      if (errorCallback) {
+        errorCallback(convertTizenFileError(error));
+      }
+    });
   }
 };
 
 cordova.define('cordova-plugin-file.tizen.fileSystems-roots', function(require, exports, module) {
 // TODO: remove -> end
 
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
 var channel = require('cordova/channel');
 
 channel.waitForInitialization('onGetRootsReady');
 channel.onCordovaReady.subscribe(function() {
-  rootsUtils.getRoots(function () {
+  rootUtils.getRoots(function () {
     channel.initializationComplete('onGetRootsReady');
   });
 });
 
 module.exports = {
   requestAllFileSystems: function(successCallback, errorCallback, args) {
-    rootsUtils.getRoots(successCallback);
+    rootUtils.getRoots(successCallback);
   }
 };
 
@@ -18,6 +18,8 @@
 cordova.define('cordova-plugin-file.tizen.requestFileSystem', function(require, exports, module) {
 // TODO: remove -> end
 
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
 module.exports = {
   requestFileSystem: function(successCallback, errorCallback, args) {
     var type = args[0];
@@ -45,7 +47,7 @@ module.exports = {
             // both filesystems are located on internal storage
             if ('INTERNAL' === r.units[i].type) {
               if (size < r.units[i].availableCapacity) {
-                rootsUtils.getRoots(function(roots) {
+                rootUtils.getRoots(function(roots) {
                   for (var i = 0; i < roots.length; ++i) {
                     if (fsName === roots[i].filesystemName) {
                       successCallback({ 'name': fsName, 'root': roots[i] });
 cordova.define('cordova-plugin-file.tizen.resolveLocalFileSystemURI', function(require, exports, module) {
 // TODO: remove -> end
 
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
 var filePrefix = 'file://';
 
 module.exports = {
   resolveLocalFileSystemURI: function(successCallback, errorCallback, args) {
-    var path = rootsUtils.internalUrlToNativePath(args[0]);
+    var path = rootUtils.internalUrlToNativePath(args[0]);
 
     if (!path) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
@@ -30,22 +33,22 @@ module.exports = {
     }
 
     function onResolve(file) {
-      var filesystem = rootsUtils.findFilesystem(file.toURI());
+      var filesystem = rootUtils.findFilesystem(file.toURI());
 
-      var entry = rootsUtils.createEntry(file, filesystem.filesystemName);
+      var entry = rootUtils.createEntry(file, filesystem.filesystemName);
       entry.isDirectory = file.isDirectory;
 
       successCallback(entry);
     }
 
     function onError(error) {
-      errorCallback && errorCallback(ConvertTizenFileError(error));
+      errorCallback && errorCallback(convertTizenFileError(error));
     }
 
     tizen.filesystem.resolve(path, onResolve, onError, 'r');
   },
   _getLocalFilesystemPath: function(successCallback, errorCallback, args) {
-    var path = rootsUtils.internalUrlToNativePath(args[0]);
+    var path = rootUtils.internalUrlToNativePath(args[0]);
 
     if (!path) {
       errorCallback && errorCallback(FileError.ENCODING_ERR);
similarity index 94%
rename from src/file/js/rootsUtils.js
rename to src/lib/plugins/cordova-plugin-file/tizen/rootUtils.js
index e673da5..294ee61 100644 (file)
  *    limitations under the License.
  */
 
-var rootsUtils = (function() {
+// TODO: remove when added to public cordova repository -> begin
+cordova.define('cordova-plugin-file.tizen.rootUtils', function(require, exports, module) {
+// TODO: remove -> end
+
+var rootUtils = (function() {
   var filePrefix = 'file:///';
 
   function stripTrailingSlash(str) {
@@ -210,3 +214,9 @@ var rootsUtils = (function() {
     internalUrlToNativePath: internalUrlToNativePath
   };
 })();
+
+module.exports = rootUtils;
+
+//TODO: remove when added to public cordova repository -> begin
+});
+//TODO: remove -> end