[Filesystem] File.createFile JS part
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Thu, 19 Feb 2015 12:07:50 +0000 (13:07 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 24 Feb 2015 14:39:57 +0000 (23:39 +0900)
[Verification]
Should create file in given directory

[Depends on]
http://168.219.209.56/gerrit/#/c/20590/

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

index a60fee6..7582a57 100644 (file)
@@ -344,18 +344,34 @@ File.prototype.createFile = function(relativeFilePath) {
     {name: 'relativeFilePath', type: types_.STRING}
   ]);
 
-  var data = {
-    relativeFilePath: args.relativeFilePath
-  };
+  if (this.isFile) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR,
+        'File object which call this method is not directory');
+  }
+
+  if (!this.f_isCorrectRelativePath(args.relativeFilePath) || this.mode === 'r') {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR,
+        'Invalid path or readonly acces');
+  }
 
-  var result = native_.callSync('File_createFile', data);
+  var _outputPath = this.fullPath + '/' + args.relativeFilePath;
+  var _outputRealPath = commonFS_.toRealPath(_outputPath);
+  var _resultExist = native_.callSync('File_statSync', {location: _outputRealPath});
+
+  if (native_.isSuccess(_resultExist)) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, 'Overwrite is not allowed');
+  }
 
+  var result = native_.callSync('File_createSync', {location: _outputRealPath});
   if (native_.isFailure(result)) {
     throw native_.getErrorObject(result);
   }
 
-  var returnObject = new File(native_.getResultObject(result));
-  return returnObject;
+  var _result = native_.callSync('File_statSync', {location: _outputRealPath});
+  var _statObj = native_.getResultObject(_result);
+  var _fileInfo = commonFS_.getFileInfo(_outputPath, _statObj, false, this.mode);
+
+  return new File(_fileInfo);
 
 };