[Service] Change a way to apply virtual path 44/260944/4
authorDongHyun Song <dh81.song@samsung.com>
Wed, 7 Jul 2021 08:53:21 +0000 (17:53 +0900)
committerDongHyun Song <dh81.song@samsung.com>
Wed, 7 Jul 2021 09:57:55 +0000 (09:57 +0000)
Not only tizen.filesystem, File object of webapis can use virtual
path. But wrtjs side cannot access File object prototype directly

Thus, basically, if we can change virtual path map in webapis side,
that is best solution.

Reference:
https://review.tizen.org/gerrit/#/c/platform/core/api/webapi-plugins/+/260943/2

Change-Id: I858ebe853ddd719515dc30616f8f92d8ba91ace1
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
wrt_app/service/device_api_router.ts

index ae2fd53..5dda076 100644 (file)
@@ -309,29 +309,12 @@ export class DeviceAPIRouter {
     }
   }
 
-  injectVirtualRootResolver(func: Function) {
-    return (...args: any[]) => {
-      if (args.length && !(args[0] === null || args[0] === undefined)) {
-        args[0] = wrt.resolveVirtualRoot(this.getServiceId(), args[0]);
-        console.log('updated argument[0] : ' + args[0]);
-      }
-      return func.apply(global.tizen.filesystem, args);
-    }
-  }
-
   refineFilesystemApis() {
-    global.tizen.filesystem.resolve = this.injectVirtualRootResolver(global.tizen.filesystem.resolve);
-    global.tizen.filesystem.listDirectory = this.injectVirtualRootResolver(global.tizen.filesystem.listDirectory);
-    global.tizen.filesystem.createDirectory = this.injectVirtualRootResolver(global.tizen.filesystem.createDirectory);
-    global.tizen.filesystem.deleteDirectory = this.injectVirtualRootResolver(global.tizen.filesystem.deleteDirectory);
-    global.tizen.filesystem.openFile = this.injectVirtualRootResolver(global.tizen.filesystem.openFile);
-    global.tizen.filesystem.deleteFile = this.injectVirtualRootResolver(global.tizen.filesystem.deleteFile);
-    global.tizen.filesystem.moveFile = this.injectVirtualRootResolver(global.tizen.filesystem.moveFile);
-    global.tizen.filesystem.copyFile = this.injectVirtualRootResolver(global.tizen.filesystem.copyFile);
-    global.tizen.filesystem.isFile = this.injectVirtualRootResolver(global.tizen.filesystem.isFile);
-    global.tizen.filesystem.toURI = this.injectVirtualRootResolver(global.tizen.filesystem.toURI);
-    global.tizen.filesystem.isDirectory = this.injectVirtualRootResolver(global.tizen.filesystem.isDirectory);
-    global.tizen.filesystem.pathExists = this.injectVirtualRootResolver(global.tizen.filesystem.pathExists);
+    let virtualPath = ['wgt-private', 'wgt-private-tmp', 'wgt-package'];
+    virtualPath.forEach(name => {
+      let realPath = wrt.resolveVirtualRoot(this.getServiceId(), name);
+      global.tizen.filesystem.setVirtualPath?.(name, realPath, 'INTERVAL', 'MOUNTED');
+    });
   }
 
   refineXwalkUtilApis() {