[Filesystem] List of virtual roots for resolve function fixed. 53/214853/2
authorRafal Walczyna <r.walczyna@samsung.com>
Tue, 24 Sep 2019 14:23:38 +0000 (16:23 +0200)
committerRafal Walczyna <r.walczyna@samsung.com>
Fri, 27 Sep 2019 07:30:26 +0000 (09:30 +0200)
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 <r.walczyna@samsung.com>
src/filesystem/filesystem_instance.cc
src/filesystem/filesystem_instance.h
src/filesystem/filesystem_manager.cc
src/filesystem/filesystem_manager.h
src/filesystem/js/common.js

index 6c2367f..d8b69fc 100644 (file)
@@ -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<common::VirtualRoot>& 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,
index 07fb8fa..34c28ed 100644 (file)
@@ -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);
index 5050a0a..4a2186b 100644 (file)
@@ -248,11 +248,11 @@ void FilesystemManager::StatPath(const std::string& path,
   success_cb(statData);
 }
 
-void FilesystemManager::GetVirtualRoots(
-    const std::function<void(const common::VirtualRoots&)>& success_cb,
+void FilesystemManager::FetchAllStorages(
+    const std::function<void(const common::VirtualStorages&)>& success_cb,
     const std::function<void(FilesystemError)>& error_cb) {
   ScopeLogger();
-  success_cb(fs_provider_.GetVirtualPaths());
+  success_cb(fs_provider_.GetAllStorages());
 }
 
 void FilesystemManager::CreateFile(const std::string& path,
index e0d2d12..2a83097 100644 (file)
@@ -62,7 +62,7 @@ class FilesystemManager {
   void FetchStorages(const std::function<void(const common::Storages&)>& success_cb,
                      const std::function<void(FilesystemError)>& error_cb);
 
-  void GetVirtualRoots(const std::function<void(const common::VirtualRoots&)>& success_cb,
+  void FetchAllStorages(const std::function<void(const common::VirtualStorages&)>& success_cb,
                        const std::function<void(FilesystemError)>& error_cb);
 
   void CreateFile(const std::string& path,
index 30dc359..1817a21 100644 (file)
@@ -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;
     }