From: Piotr Kosko
Date: Thu, 27 Aug 2015 09:47:18 +0000 (+0900)
Subject: [FileSystem] Fix issue about destination path in copyTo() method.
X-Git-Tag: submit/tizen/20151026.073646^2^2~25^2
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c638c43c0732dc41f1fd97a986047b7b3afc5527;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[FileSystem] Fix issue about destination path in copyTo() method.
cherry-pick from tizen_2.4_tv_product_migration branch.
Issue : copyTo() method returns error, when the destination path is virtual path without '/'
Change-Id: Ibb87064acccada243bff85298401a6639c1b44c6
Signed-off-by: Piotr Kosko
---
diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js
index 6bcbe42d..539f3ad6 100755
--- a/src/filesystem/js/file.js
+++ b/src/filesystem/js/file.js
@@ -364,15 +364,6 @@ File.prototype.copyTo = function(originFilePath, destinationFilePath, overwrite,
return;
}
- var lastChar;
- var addFilenameToPath = false;
- if (args.destinationFilePath.length) {
- lastChar = args.destinationFilePath.substr(args.destinationFilePath.length - 1);
- if (lastChar === '/') {
- addFilenameToPath = true;
- }
- }
-
var _realOriginalPath = commonFS_.toRealPath(args.originFilePath);
var _realDestinationPath = commonFS_.toRealPath(args.destinationFilePath);
@@ -403,13 +394,45 @@ File.prototype.copyTo = function(originFilePath, destinationFilePath, overwrite,
}
var _oldNode = native_.getResultObject(resultOldPath);
- if (_oldNode.isFile && addFilenameToPath) {
- _realDestinationPath = _realDestinationPath + _realOriginalPath.split('/').pop();
+ var addFileName = false;
+ var lastChar = _realDestinationPath.substr(_realDestinationPath.length -1);
+
+ var resultNewPath = native_.callSync('File_statSync', {location: _realDestinationPath});
+ if (native_.isSuccess(resultNewPath)) {
+ var _newNode = native_.getResultObject(resultNewPath);
+ if (_newNode.isDirectory) {
+ if (lastChar !== '/') {
+ _realDestinationPath += '/';
+ }
+ addFileName = true;
+ }
+ } else {
+ var destinationFileName, destinationDirectoryPath;
+ if (lastChar !== '/') {
+ destinationFileName = _realDestinationPath.split('/').pop();
+ }
+ destinationDirectoryPath = _realDestinationPath.substr(0, _realDestinationPath.lastIndexOf('/') + 1);
+
+ var resultDestinationDirectory = native_.callSync('File_statSync', {location: destinationDirectoryPath});
+ if (native_.isFailure(resultDestinationDirectory)) {
+ setTimeout(function() {
+ native_.callIfPossible(args.onerror, native_.getErrorObject(resultDestinationDirectory));
+ }, 0);
+ return;
+ }
+
+ if (destinationFileName.length == 0) {
+ addFileName = true;
+ }
+ }
+
+ if (_oldNode.isFile && addFileName) {
+ _realDestinationPath += _realOriginalPath.split('/').pop();
}
if (!args.overwrite) {
- var resultNewPath = native_.callSync('File_statSync', {location: _realDestinationPath});
- if (native_.isSuccess(resultNewPath)) {
+ var resultPath = native_.callSync('File_statSync', {location: _realDestinationPath});
+ if (native_.isSuccess(resultPath)) {
setTimeout(function() {
native_.callIfPossible(args.onerror,
new WebAPIException(WebAPIException.IO_ERR, 'Overwrite is not allowed'));