From: Rafal Walczyna Date: Tue, 24 Sep 2019 14:23:38 +0000 (+0200) Subject: [Filesystem] List of virtual roots for resolve function fixed. X-Git-Tag: submit/tizen/20190930.141103~3^2^2^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3fd1f205f97a83b82c817a57fde957077f0b8816;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] List of virtual roots for resolve function fixed. Current implementation of virtual roots list did not include internal0 or external memory i.e. SDCard or USBDrive. It results in not working resolve() function, when location to resolve was on external memory. Verification: TCT - 100 % pass. Change-Id: I11c2537a7f5643f8c9ccfe2f45be9f3bce3edf00 Signed-off-by: Rafal Walczyna --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index 6c2367fd..d8b69fc4 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -57,7 +57,7 @@ FilesystemInstance::FilesystemInstance() { REGISTER_SYNC("File_writeBytes", FileWriteBytes); REGISTER_SYNC("File_writeBase64", FileWriteBase64); REGISTER_SYNC("File_writeString", FileWriteString); - REGISTER_SYNC("Filesystem_fetchVirtualRoots", FilesystemFetchVirtualRoots); + REGISTER_SYNC("Filesystem_fetchAllStorages", FilesystemFetchAllStorages) REGISTER_SYNC("FileSystemManager_addStorageStateChangeListener", StartListening); REGISTER_SYNC("FileSystemManager_removeStorageStateChangeListener", StopListening); REGISTER_SYNC("FileSystemManager_fetchStorages", FileSystemManagerFetchStorages); @@ -512,15 +512,15 @@ void FilesystemInstance::FileStatSync(const picojson::value& args, picojson::obj FilesystemManager::GetInstance().StatPath(location, onSuccess, onError); } -void FilesystemInstance::FilesystemFetchVirtualRoots(const picojson::value& args, +void FilesystemInstance::FilesystemFetchAllStorages(const picojson::value& args, picojson::object& out) { ScopeLogger(); - auto onSuccess = [&](const std::vector& result) { + auto onSuccess = [&](const common::VirtualStorages& result) { ScopeLogger("Entered into asynchronous function, onSuccess"); picojson::array roots; for (const auto& root : result) { - roots.push_back(root.ToJson()); + roots.push_back(root->ToJson()); } ReportSuccess(picojson::value(roots), out); }; @@ -530,7 +530,7 @@ void FilesystemInstance::FilesystemFetchVirtualRoots(const picojson::value& args PrepareError(e, out); }; - FilesystemManager::GetInstance().GetVirtualRoots(onSuccess, onError); + FilesystemManager::GetInstance().FetchAllStorages(onSuccess, onError); } void FilesystemInstance::FileSystemManagerFetchStorages(const picojson::value& args, diff --git a/src/filesystem/filesystem_instance.h b/src/filesystem/filesystem_instance.h index 07fb8fa8..34c28ed6 100644 --- a/src/filesystem/filesystem_instance.h +++ b/src/filesystem/filesystem_instance.h @@ -40,7 +40,7 @@ class FilesystemInstance : public common::ParsedInstance, FilesystemStateChangeL void FileWriteBytes(const picojson::value& args, picojson::object& out); void FileWriteBase64(const picojson::value& args, picojson::object& out); void FileWriteString(const picojson::value& args, picojson::object& out); - void FilesystemFetchVirtualRoots(const picojson::value& args, picojson::object& out); + void FilesystemFetchAllStorages(const picojson::value& args, picojson::object& out); void FileSystemManagerFetchStorages(const picojson::value& args, picojson::object& out); void FileSystemManagerMakeDirectory(const picojson::value& args, picojson::object& out); void FileSystemManagerMakeDirectorySync(const picojson::value& args, picojson::object& out); diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc index 5050a0ae..4a2186bc 100644 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -248,11 +248,11 @@ void FilesystemManager::StatPath(const std::string& path, success_cb(statData); } -void FilesystemManager::GetVirtualRoots( - const std::function& success_cb, +void FilesystemManager::FetchAllStorages( + const std::function& success_cb, const std::function& error_cb) { ScopeLogger(); - success_cb(fs_provider_.GetVirtualPaths()); + success_cb(fs_provider_.GetAllStorages()); } void FilesystemManager::CreateFile(const std::string& path, diff --git a/src/filesystem/filesystem_manager.h b/src/filesystem/filesystem_manager.h index e0d2d12b..2a830977 100644 --- a/src/filesystem/filesystem_manager.h +++ b/src/filesystem/filesystem_manager.h @@ -62,7 +62,7 @@ class FilesystemManager { void FetchStorages(const std::function& success_cb, const std::function& error_cb); - void GetVirtualRoots(const std::function& success_cb, + void FetchAllStorages(const std::function& success_cb, const std::function& error_cb); void CreateFile(const std::string& path, diff --git a/src/filesystem/js/common.js b/src/filesystem/js/common.js index 30dc3594..1817a219 100644 --- a/src/filesystem/js/common.js +++ b/src/filesystem/js/common.js @@ -95,8 +95,7 @@ var commonFS_ = (function() { if (cacheReady) { return; } - - var result = native_.callSync('Filesystem_fetchVirtualRoots', {}); + var result = native_.callSync('Filesystem_fetchAllStorages', {}); if (native_.isFailure(result)) { throw native_.getErrorObject(result); } @@ -106,8 +105,8 @@ var commonFS_ = (function() { cacheVirtualToReal[virtualRoots[i].name] = { path: virtualRoots[i].path, label: virtualRoots[i].name, - type: FileSystemStorageType.INTERNAL, - state: FileSystemStorageState.MOUNTED + type: virtualRoots[i].type, + state: virtualRoots[i].state }; } // initalize home directory for correct mapping global paths from tizen 2.4 @@ -267,14 +266,24 @@ var commonFS_ = (function() { } initCache(); - + // find virtual root with longest path + var foundLength = 0; + var foundVirtualRoot; + var foundVirtualPath; for (var virtual_root in cacheVirtualToReal) { - var real_root_path = cacheVirtualToReal[virtual_root].path; - if (_virtualPath.indexOf(real_root_path, 0) === 0) { - return _virtualPath.replace(real_root_path, virtual_root); + var real_root_path = cacheVirtualToReal[virtual_root].path + if(_virtualPath.indexOf(real_root_path, 0) === 0) { + var currentLength = real_root_path.length; + if(currentLength > foundLength) { + foundLength = currentLength; + foundVirtualRoot = virtual_root; + foundVirtualPath = real_root_path + } } } - + if(foundLength != 0) { + return _virtualPath.replace(foundVirtualPath, foundVirtualRoot); + } return _virtualPath; }