[Filesystem] createDirectory JS part
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Wed, 18 Feb 2015 13:59:16 +0000 (14:59 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 24 Feb 2015 14:17:01 +0000 (23:17 +0900)
[Verification]
tizen.filesystem.resolve(
  'images/',
  function (dir) {
    var newDir = dir.createDirectory("newDir");
    console.log(newDir.name === 'newDir');
  }, function (e) {
  console.log("filesystem.resolve Error callback: " + e.message);
}, "rw");
//should create directory and return true

[Depends On]
http://168.219.209.56/gerrit/#/c/20563/

Change-Id: Ib3cfe7a5608f04a5d87724ec57408a54c6d5fd66
Signed-off-by: Pawel Kaczmarek <p.kaczmarek3@samsung.com>
src/filesystem/js/file.js

index 76301cb..9282013 100644 (file)
@@ -316,19 +316,40 @@ File.prototype.createDirectory = function(dirPath) {
     {name: 'dirPath', type: types_.STRING}
   ]);
 
-  var data = {
-    dirPath: args.dirPath
-  };
+  if (!arguments.length || !args.dirPath.length) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+        'Invalid path');
+  }
+  var _newPath = this.fullPath + '/' + args.dirPath,
+          _statObj,
+          _fileInfo,
+          _realNewPath = commonFS_.toRealPath(_newPath);
+
+  if (this.isDirectory) {
+    if (this.mode === 'r') {
+      throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+          'Invalid path or readonly access');
+    }
 
-  var result = native_.callSync('File_createDirectory', data);
+    var _resultExist = native_.callSync('File_statSync', {location: _realNewPath});
+    if (native_.isSuccess(_resultExist)) {
+      throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, 'Directory already exist');
+    }
 
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
-  }
+    var result = native_.callSync('FileSystemManager_mkdirSync', {location: _realNewPath});
+    if (native_.isFailure(result)) {
+      throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, native_.getErrorObject(result));
+    }
 
-  var returnObject = new File(native_.getResultObject(result));
-  return returnObject;
+    var _result = native_.callSync('File_statSync', {location: _realNewPath});
+    _statObj = native_.getResultObject(_result);
 
+    _fileInfo = commonFS_.getFileInfo(_realNewPath, _statObj, false, this.mode);
+    return new File(_fileInfo);
+  } else {
+    throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR,
+        'File object which call this method is not directory');
+  }
 };
 
 File.prototype.createFile = function(relativeFilePath) {