[Filesystem] File.resolve
authorPawel Kaczmarek <p.kaczmarek3@samsung.com>
Mon, 23 Feb 2015 15:05:43 +0000 (16:05 +0100)
committerPawel Kaczmarek <p.kaczmarek3@samsung.com>
Mon, 23 Feb 2015 15:05:43 +0000 (16:05 +0100)
[Verification]
tizen.filesystem.resolve(
  'documents',
  function(dir) {
    var file = dir.resolve("file.txt");
    console.log('file: ', file);
  },
  function(e) { console.log("Error" + e.message);},
  "rw");
//should return file object

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

index dbb61fb4a243fd79a4402ed11e94119aa59439ec..55b8e3be29570a8476a528fd72d318bd79127b96 100644 (file)
@@ -230,18 +230,24 @@ File.prototype.resolve = function(filePath) {
     {name: 'filePath', type: types_.STRING}
   ]);
 
-  var data = {
-    filePath: args.filePath
-  };
-
-  var result = native_.callSync('File_resolve', data);
+  if (this.isFile) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR,
+        'File object which call this method is not directory');
+  }
 
-  if (native_.isFailure(result)) {
-    throw native_.getErrorObject(result);
+  if (!this.f_isCorrectRelativePath(args.filePath)) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR, 'Invalid path');
   }
 
-  var returnObject = new File(native_.getResultObject(result));
-  return returnObject;
+  var _newPath = this.fullPath + '/' + args.filePath;
+  var _realPath = commonFS_.toRealPath(_newPath);
+  var _result = native_.callSync('File_statSync', {location: _realPath});
+  if (native_.isFailure(_result)) {
+    throw new tizen.WebAPIException(tizen.WebAPIException.IO_ERR, native_.getErrorObject(_result));
+  }
+  var _statObj = native_.getResultObject(_result);
+  var _fileInfo = commonFS_.getFileInfo(_newPath, _statObj, false, this.mode);
+  return new File(_fileInfo);
 
 };