From e664b9819758fed1a213dcb9bf83f51d2b59dfaa Mon Sep 17 00:00:00 2001 From: "taekeun.kang" Date: Mon, 19 Oct 2015 16:34:42 +0900 Subject: [PATCH] [Filesystem] sync tizen_2.4 branch latest filesystem source code. Change-Id: I9fb2ad12da1924c02f6c6fd649333d9a4e91b4b9 Signed-off-by: taekeun.kang --- src/common/current_application.cc | 4 +- src/common/virtual_fs.cc | 7 +-- src/filesystem/filesystem_instance.cc | 13 +++++- src/filesystem/filesystem_utils.cc | 8 ++-- src/filesystem/js/common.js | 8 ++-- src/filesystem/js/file.js | 59 ++++++++++++++++++------ src/filesystem/js/file_system_manager.js | 1 + 7 files changed, 73 insertions(+), 27 deletions(-) diff --git a/src/common/current_application.cc b/src/common/current_application.cc index fc08be08..85910ccf 100755 --- a/src/common/current_application.cc +++ b/src/common/current_application.cc @@ -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); diff --git a/src/common/virtual_fs.cc b/src/common/virtual_fs.cc index 78d5f9d3..01991b1f 100755 --- a/src/common/virtual_fs.cc +++ b/src/common/virtual_fs.cc @@ -94,7 +94,8 @@ common::optional 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; diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 5e4d10b9..93ceb1d7 100755 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -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; } } diff --git a/src/filesystem/filesystem_utils.cc b/src/filesystem/filesystem_utils.cc index c2889350..6fd4fcdc 100755 --- a/src/filesystem/filesystem_utils.cc +++ b/src/filesystem/filesystem_utils.cc @@ -22,11 +22,11 @@ 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); diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js index ed45ada6..1bc8ed30 100755 --- a/src/filesystem/js/common.js +++ b/src/filesystem/js/common.js @@ -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, diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index c7d80b18..278fdf60 100755 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -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() { diff --git a/src/filesystem/js/file_system_manager.js b/src/filesystem/js/file_system_manager.js index e5e3c8b8..6f24d906 100755 --- a/src/filesystem/js/file_system_manager.js +++ b/src/filesystem/js/file_system_manager.js @@ -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); -- 2.34.1