[Filesystem] sync tizen_2.4 branch latest filesystem source code.
authortaekeun.kang <taekeun.kang@samsung.com>
Mon, 19 Oct 2015 07:34:42 +0000 (16:34 +0900)
committertaekeun.kang <taekeun.kang@samsung.com>
Tue, 20 Oct 2015 12:43:32 +0000 (21:43 +0900)
Change-Id: I9fb2ad12da1924c02f6c6fd649333d9a4e91b4b9
Signed-off-by: taekeun.kang <taekeun.kang@samsung.com>
src/common/current_application.cc
src/common/virtual_fs.cc
src/filesystem/filesystem_instance.cc
src/filesystem/filesystem_utils.cc
src/filesystem/js/common.js
src/filesystem/js/file.js
src/filesystem/js/file_system_manager.js

index fc08be08d58c1efebe22a04316ce3f1e919aeb86..85910ccf690cfe488e1aa606ddb86d15ac97f4d4 100755 (executable)
@@ -62,7 +62,7 @@ std::string CurrentApplication::FetchApplicationId() const {
   if ((APP_MANAGER_ERROR_NONE == ret) && (nullptr != tmp_str)) {
     app_id = tmp_str;
   } else {
-    LoggerE("Failed to get application ID.");
+    LoggerE("Failed to get application ID: %d (%s)", ret, get_error_message(ret));
   }
 
   free(tmp_str);
@@ -81,7 +81,7 @@ std::string CurrentApplication::FetchPackageId() const {
   if ((PACKAGE_MANAGER_ERROR_NONE == ret) && (nullptr != tmp_str)) {
     package_id = tmp_str;
   } else {
-    LoggerE("Failed to get package ID.");
+    LoggerE("Can't get package name from app info: %d (%s)", ret, get_error_message(ret));
   }
 
   free(tmp_str);
index 78d5f9d3b37ca8ca492c529996917183bc223e79..01991b1f25f35c94fdb47cb473440dc2e606a368 100755 (executable)
@@ -94,7 +94,8 @@ common::optional<std::string> GetRootDir() {
   app_info_h app_info;
   int err = app_info_create(app_id.c_str(), &app_info);
   if (APP_MANAGER_ERROR_NONE != err) {
-    LoggerE("Can't create app info handle from appId (%s)", app_id.c_str());
+    LoggerE("Can't create app info handle from appId (%s): %d (%s)", app_id.c_str(), err,
+            get_error_message(err));
     return nullptr;
   }
   SCOPE_EXIT {
@@ -232,8 +233,8 @@ VirtualFs::VirtualFs() : app_root_(GetRootDir()) {
 
   int err = storage_foreach_device_supported(OnStorageDeviceSupported, nullptr);
 
-  if (err != STORAGE_ERROR_NONE) {
-    LoggerE("Unknown Error on getting storage paths");
+  if (STORAGE_ERROR_NONE != err) {
+    LoggerE("Unknown Error on getting storage paths %d (%s)", err, get_error_message(err));
   }
 
   int id = -1;
index 5e4d10b9b3ea414f7e8f2963db195a806187c358..93ceb1d7c16b5a99043efa92e2561c1ec040f50a 100755 (executable)
@@ -597,31 +597,40 @@ void FilesystemInstance::PrepareError(const FilesystemError& error, picojson::ob
   LoggerD("enter");
   switch (error) {
     case FilesystemError::None:
+      LoggerE("UnknownException - PLATFORM ERROR");
       ReportError(UnknownException("PLATFORM ERROR"), out);
       break;
     case FilesystemError::NotFound:
+      LoggerE("NotFoundException - PLATFORM ERROR");
       ReportError(NotFoundException("PLATFORM ERROR"), out);
       break;
     case FilesystemError::FileExists:
+      LoggerE("IOException - File already exists");
       ReportError(IOException("File already exists"), out);
       break;
     case FilesystemError::DirectoryExists:
+      LoggerE("IOException - Directory already exists");
       ReportError(IOException("Directory already exists"), out);
       break;
     case FilesystemError::PermissionDenied:
+      LoggerE("IOException - Permission denied");
       ReportError(IOException("Permission denied"), out);
       break;
     case FilesystemError::IOError:
+      LoggerE("IOException - IO Error");
       ReportError(IOException("IO Error"), out);
       break;
     case FilesystemError::Other:
-      ReportError(UnknownException("PLATFORM ERROR"), out);
+      LoggerE("UnknownException - PLATFORM ERROR other");
+      ReportError(UnknownException("PLATFORM ERROR other"), out);
       break;
     case FilesystemError::InvalidValue:
+      LoggerE("InvalidValuesException - PLATFORM ERROR");
       ReportError(InvalidValuesException("PLATFORM ERROR"), out);
       break;
     default:
-      ReportError(UnknownException("PLATFORM ERROR"), out);
+      LoggerE("UnknownException - PLATFORM ERROR default");
+      ReportError(UnknownException("PLATFORM ERROR default"), out);
       break;
   }
 }
index c28893500e9fe8c5db60246f908348a2a7495aa8..6fd4fcdc2351cb9bd6b4e54641feddf8dd92f736 100755 (executable)
 namespace FilesystemUtils {
 std::string get_storage_dir_path(int id, storage_directory_e typeToCheck) {
   LoggerD("Enter");
-  int result = STORAGE_ERROR_NONE;
   char* platformPath = NULL;
-  result = storage_get_directory(id, typeToCheck, &platformPath);
-  if (result != STORAGE_ERROR_NONE) {
-    LoggerD("Cannot retrieve path for type %i", typeToCheck);
+  int result = storage_get_directory(id, typeToCheck, &platformPath);
+  if (STORAGE_ERROR_NONE != result) {
+    LoggerE("Cannot retrieve path for type %i: %d (%s)", typeToCheck, result,
+            get_error_message(result));
     return std::string();
   }
   std::string path = std::string(platformPath);
index ed45ada63c0ce502f71ac65dcdbd04daaa6562b4..1bc8ed305d4181c0906e5b850dbfcb77f4605c31 100755 (executable)
@@ -218,12 +218,13 @@ var commonFS_ = (function() {
   }
 
   function f_isSubDir(fullPathToCheck, fullPath) {
-    return (-1 !== fullPathToCheck.indexOf(toRealPath(fullPath)));
+    var realFullPath = toRealPath(fullPath);
+    return ((-1 !== fullPathToCheck.indexOf(realFullPath)) && (fullPathToCheck !== realFullPath));
   };
 
   function f_isCorrectRelativePath(relativePath) {
-    return ((-1 === relativePath.indexOf('/')) &&
-        (-1 === relativePath.indexOf('\\')) &&
+    return ((0 !== relativePath.indexOf('/')) &&
+        (0 !== relativePath.indexOf('\\')) &&
         (-1 === relativePath.indexOf('?')) &&
         (-1 === relativePath.indexOf('*')) &&
         (-1 === relativePath.indexOf(':')) &&
@@ -260,6 +261,7 @@ var commonFS_ = (function() {
   }
 
   return {
+    clearCache: clearCache,
     toRealPath: toRealPath,
     toVirtualPath: toVirtualPath,
     getFileInfo: getFileInfo,
index c7d80b18cc2baaaa4b5933d7dd3502142c5b6726..278fdf60587d94399f2f71e4f85d18c792b657cf 100755 (executable)
@@ -365,15 +365,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);
 
@@ -404,13 +395,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'));
@@ -728,6 +751,16 @@ File.prototype.deleteDirectory = function(directoryPath, recursive, onsuccess, o
   }
 
   var _myPath = commonFS_.toRealPath(args.directoryPath);
+
+  if (_myPath !== undefined && !commonFS_.f_isSubDir(_myPath, this.fullPath)) {
+    var m1 = 'Deleted directory should be under the current directory: ' + this.fullPath;
+    setTimeout(function() {
+      native_.callIfPossible(args.onerror,
+          new WebAPIException(WebAPIException.INVALID_VALUES_ERR, m1));
+    }, 0);
+    return;
+  }
+
   var _result = native_.callSync('File_statSync', {location: _myPath});
   if (native_.isFailure(_result)) {
     setTimeout(function() {
index e5e3c8b8bc1a68db2bdb21242087b2a9301d462a..6f24d906d81ff5c8349d886f554b734428ca05d8 100755 (executable)
@@ -160,6 +160,7 @@ function nextCallbackId() {
 }
 
 function _StorageStateChangeListener(result) {
+  commonFS_.clearCache();
   var storage = new FileSystemStorage(result);
   for (var id in callbacks) {
     native_.callIfPossible(callbacks[id], storage);