diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000000000000000000000000000000000000..51c63e295e0232f7095a8ee8e03713837e37f419
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,15 @@
+*.tgz filter=lfs diff=lfs merge=lfs -text
+*.trp filter=lfs diff=lfs merge=lfs -text
+*.apk filter=lfs diff=lfs merge=lfs -text
+*.jar filter=lfs diff=lfs merge=lfs -text
+*.mp4 filter=lfs diff=lfs merge=lfs -text
+*.zip filter=lfs diff=lfs merge=lfs -text
+*.asm filter=lfs diff=lfs merge=lfs -text
+*.8svn filter=lfs diff=lfs merge=lfs -text
+*.9svn filter=lfs diff=lfs merge=lfs -text
+*.dylib filter=lfs diff=lfs merge=lfs -text
+*.exe filter=lfs diff=lfs merge=lfs -text
+*.a filter=lfs diff=lfs merge=lfs -text
+*.so filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text
+*.dll filter=lfs diff=lfs merge=lfs -text
diff --git a/LICENSE b/LICENSE
index 4947287f7b5ccb5d1e8b7b2d3aa5d89f322c160d..2bb9ad240fa04c8cf706a4901c4807878e90c2dc 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,3 @@
-
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
diff --git a/README.md b/README.md
index 76562969b350c0a8a0d32232860b134f43e815c8..55e6ee10c334df771a9acec62c42f9e386b3b3db 100644
--- a/README.md
+++ b/README.md
@@ -1,36 +1,280 @@
-# storage_app_file_manager
+# Distributed File
-#### Description
-{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
+- [Introduction](#section104mcpsimp)
+ - [Architecture](#section110mcpsimp)
-#### Software Architecture
-Software architecture description
+- [Directory Structure](#section113mcpsimp)
+- [Constraints](#section117mcpsimp)
+- [Usage](#section125mcpsimp)
+ - [Available APIs](#section127mcpsimp)
+ - [Usage Guidelines](#section149mcpsimp)
-#### Installation
+- [Repositories Involved](#section178mcpsimp)
-1. xxxx
-2. xxxx
-3. xxxx
+## Introduction
-#### Instructions
+Currently, the Distributed File subsystem provides apps with JavaScript APIs for I/O capabilities, including APIs for managing files and directories, obtaining file information, reading and writing data streams of files, and receiving URIs rather than absolute paths.
-1. xxxx
-2. xxxx
-3. xxxx
+### Architecture
-#### Contribution
+Currently, the Distributed File subsystem provides only local JavaScript file APIs for apps through the FileIO and File modules. The Distributed File subsystem uses LibN to abstract APIs at the NAPI layer, providing basic capabilities such as the basic type system, memory management, and general programming models for the subsystem. This subsystem depends on the engine layer of the JS application development framework to provide the capability of converting JavaScript APIs into C++ code, depends on the application framework to provide app-related directories, and depends on the GLIBC runtimes to provide I/O capabilities.
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
+**Figure 1** Distributed File subsystem architecture
+
+## Directory Structure
-#### Gitee Feature
+```
+foundation/distributeddatamgr/distributedfile
+└── interfaces # APIs
+ └── kits # APIs exposed externally
+```
+
+## Constraints
+
+Constraints on local I/O APIs:
+
+- Only UTF-8/16 encoding is supported.
+- The URIs cannot include external storage directories.
+
+## Usage
+
+### Available APIs
+
+Currently, the Distributed File subsystem provides APIs for accessing local files and directories. The following table describes the API types classified by function.
+
+**Table 1** API types
+
+
+
API Type
+ |
+Function
+ |
+Related Module
+ |
+Example API (Class Name.Method Name)
+ |
+
+
+Basic file API
+ |
+Creates, modifies, and accesses files, and changes file permissions based on the specified absolute paths or file descriptors.
+ |
+@OHOS.distributedfile.fileio
+ |
+accessSync
+chownSync
+chmodSync
+ |
+
+Basic directory API
+ |
+Reads directories and determines file types based on the specified absolute paths.
+ |
+@OHOS.distributedfile.fileio
+ |
+Dir.openDirSync
+ |
+
+Basic statistical API
+ |
+Collects basic statistics including the file size, access permission, and modification time based on the specified absolute paths.
+ |
+@OHOS.distributedfile.fileio
+ |
+Stat.statSync
+ |
+
+Streaming file API
+ |
+Reads and writes data streams of files based on the specified absolute paths or file descriptors.
+ |
+@OHOS.distributedfile.fileio
+ |
+Stream.createStreamSync
+Stream.fdopenStreamSync
+ |
+
+Sandbox file API
+ |
+Provides a subset or a combination of the capabilities provided by the basic file, directory, and statistical APIs based on the specified URIs.
+ |
+@system.file
+ |
+move
+copy
+list
+ |
+
+
+
+
+The URIs used in sandbox file APIs are classified into three types, as described in the following table.
+
+**Table 2** URI types
+
+
+Directory Type
+ |
+Prefix
+ |
+Access Visibility
+ |
+Description
+ |
+
+
+Temporary directory
+ |
+internal://cache/
+ |
+Current app only
+ |
+Readable and writable, and can be cleared at any time. This directory is usually used for temporary downloads or caches.
+ |
+
+Private directory of an app
+ |
+internal://app/
+ |
+Current app only
+ |
+Deleted when the app is uninstalled.
+ |
+
+External storage
+ |
+internal://share/
+ |
+All apps
+ |
+Deleted when the app is uninstalled. Other apps with granted permissions can read and write files in this directory.
+ |
+
+
+
+
+### Usage Guidelines
+
+The I/O APIs provided by the Distributed File subsystem can be classified into the following types based on the programming model:
+
+- Synchronous programming model
+
+ APIs whose names contain **Sync** are implemented as a synchronous model. When a synchronous API is called, the calling process waits until a value is returned.
+
+ The following example opens a file stream in read-only mode, attempts to read the first 4096 bytes, converts them into a UTF-8-encoded string, and then closes the file stream:
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ var ss = fileio.Stream.createStreamSync("tmp", "r")
+ buf = new ArrayBuffer(4096)
+ ss.readSync(buf)
+ console.log(String.fromCharCode.apply(null, new Uint8Array(buf)))
+ ss.closeSync()
+ }
+ catch (e) {
+ console.log(e);
+ }
+ ```
+
+
+- Asynchronous programming model: Promise
+
+ In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is not passed as their input parameter are implemented as the Promise asynchronous model. The Promise asynchronous model is one of the OHOS standard asynchronous models. When an asynchronous API using the Promise model is called, the API returns a Promise object while executing the concerned task asynchronously. The Promise object represents the asynchronous operation result. When there is more than one result, the results are returned as properties of the Promise object.
+
+ In the following example, a Promise chain is used to open a file stream in read-only mode, attempt to read the first 4096 bytes of the file, display the length of the content read, and then close the file:
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ let openedStream
+ fileio.Stream.createStream("test.txt", "r")
+ .then(function (ss) {
+ openedStream = ss;
+ return ss.read(new ArrayBuffer(4096))
+ })
+ .then(function (res) {
+ console.log(res.bytesRead);
+ console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer)))
+ return openedStream.close()
+ })
+ .then(function (undefined) {
+ console.log("Stream is closed")
+ })
+ .catch(function (e) {
+ console.log(e)
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- Asynchronous programming model: Callback
+
+ In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is directly passed as their input parameter are implemented as the callback asynchronous model. The callback asynchronous model is also one of the OHOS standard asynchronous models. When an asynchronous API with a callback passed is called, the API executes the concerned task asynchronously and returns the execution result as the input parameters of the registered callback. The first parameter is of the **undefined** or **Error** type, indicating that the execution succeeds or fails, respectively.
+
+ The following example creates a file stream asynchronously, reads the first 4096 bytes of the file asynchronously in the callback invoked when the file stream is created, and then closes the file asynchronously in the callback invoked when the file is read:
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) {
+ if (!err) {
+ ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) {
+ if (!err) {
+ console.log('readLen: ' + readLen)
+ console.log('data: ' + String.fromCharCode.apply(null, new Uint8Array(buf)))
+ } else {
+ console.log('Cannot read from the stream ' + err)
+ }
+ ss.close(function (err) {
+ console.log(`Stream is ${err ? 'not' : ''}closed`)
+ });
+ })
+ } else {
+ console.log('Cannot open the stream ' + err)
+ }
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- Asynchronous programming model: Legacy
+
+ All APIs in the **@system.file** module are implemented as the legacy asynchronous model. When calling such an API, you need to implement three callbacks \(including **success**, **fail**, and **complete**\) to be invoked when the execution is successful, fails, or is complete, respectively. If the input parameters are correct, the API calls the **success** or **fail** callback based on whether the asynchronous task is successful after the task execution is complete, and finally calls the **complete** callback.
+
+ The following example asynchronously checks whether the file pointed to by the specified URI exists and provides three callbacks to print the check result:
+
+ ```
+ import file from '@system.file'
+
+ file.access({
+ uri: 'internal://app/test.txt',
+ success: function() {
+ console.log('call access success.');
+ },
+ fail: function(data, code) {
+ console.error('call fail callback fail, code: ' + code + ', data: ' + data);
+ },
+ complete: function () {
+ console.log('call access finally.');
+ }
+ });
+
+ console.log("file access tested done")
+ ```
+
+
+## Repositories Involved
+
+**Distributed File subsystem**
+
+distributeddatamgr_distributedfile
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
diff --git a/README_zh.md b/README_zh.md
index 25fb3eb92931621d20f68452b45c55351b43c2ac..362301a666a4ca36cd4bd481264a598996157ca5 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -1,28 +1,281 @@
-# 文件访问接口
+# 分布式文件子系统
-## 简介
+- [简介](#section104mcpsimp)
+ - [系统架构](#section110mcpsimp)
+- [目录结构](#section113mcpsimp)
+- [约束](#section117mcpsimp)
+- [说明](#section125mcpsimp)
+ - [接口说明](#section127mcpsimp)
+ - [使用说明](#section149mcpsimp)
+- [相关仓](#section178mcpsimp)
-提供目录与文件管理能力,即目录和文件的访问操作接口,包括以下内容:
+## 简介
-1. 提供基础文件操作的同步和异步接口
-2. 提供目录操作的异步接口
-3. 提供流式相关操作的文件接口
-4. 提供statfs接口能力
-5. 提供目录环境相关配置接口
-6. 提供本地系统扩展接口能力
+分布式文件子系统当前向应用程序提供用于的 IO 的 JS 接口。其具体包括用于管理文件的基本文件接口,用于管理目录的基本目录接口,用于获取文件信息的统计接口,用于流式读写文件的流式接口,以及接收 URI 而非绝对路径的沙盒接口。
-## 目录
+### 系统架构
+
+当前分布式文件子系统仅面向应用提供本地 JS 文件接口,这些接口分别通过 FileIO 模块以及 File 模块提供。架构上,分布式文件子系统实现了自研的 LibN,其抽象了 NAPI 层接口,向分布式文件子系统提供包括基本类型系统、内存管理、通用编程模型在内的基本能力。本系统对外依赖 JS 开发框架提供将 JS 接口转换为 C++ 代码的能力,依赖用户程序框架提供应用相关目录,依赖 GLIBC Runtimes 提供 IO 能力。
+
+**图 1** 分布式文件子系统架构图
+
+
+## 目录结构
```
-interfaces # 接口代码
- └── kits # 对外JS接口代码
-LICENSE # 证书文件
+foundation/distributeddatamgr/distributedfile
+├── figures # 仓库图床
+└── interfaces # 接口代码
+ └── kits # 对外接口代码
```
-## 说明
+## 约束
+
+本地 IO 接口
+
+- 目前仅支持 UTF-8/16 编码;
+- 目前 URI 暂不支持外部存储目录;
+
+## 说明
+
+### 接口说明
+
+当前分布式文件子系统开放本地文件目录访问接口,按照功能,其可划分为如下几种类型:
+
+**表 1** 接口类型表
+
+
+接口类型
+ |
+接口用途
+ |
+相关模块
+ |
+接口示例(类名.方法名)
+ |
+
+
+基本文件接口
+ |
+需要用户提供绝对路径或文件描述符(fd),提供创建、修改及访问文件,或修改文件权限的能力
+ |
+@OHOS.distributedfile.fileio
+ |
+accessSync
+chownSync
+chmodSync
+ |
+
+基本目录接口
+ |
+需要用户提供绝对路径,提供读取目录及判断文件类型的能力
+ |
+@OHOS.distributedfile.fileio
+ |
+Dir.openDirSync
+ |
+
+基本Stat接口
+ |
+需要用户提供绝对路径,提供包括文件大小、访问权限、修改时间在内的基本统计信息
+ |
+@OHOS.distributedfile.fileio
+ |
+Stat.statSync
+ |
+
+流式文件接口
+ |
+需要用户提供绝对路径或文件描述符,提供流式读写文件的能力
+ |
+@OHOS.distributedfile.fileio
+ |
+Stream.createStreamSync
+Stream.fdopenStreamSync
+ |
+
+沙盒文件接口
+ |
+需要用户提供 URI,提供基本文件接口、基本目录接口及基本统计接口能力的子集能力,或这些能力的组合能力
+ |
+@system.file
+ |
+move
+copy
+list
+ |
+
+
+
+
+其中,沙盒文件接口所使用的 URI 具体可划分为三种类型:
+
+**表 2** URI类型表
+
+
+目录类型
+ |
+路径前缀
+ |
+访问可见性
+ |
+说明
+ |
+
+
+临时目录
+ |
+internal://cache/
+ |
+仅本应用可见
+ |
+可读写,随时可能清除,不保证持久性。一般用作下载临时目录或缓存目录。
+ |
+
+应用私有目录
+ |
+internal://app/
+ |
+仅本应用可见
+ |
+随应用卸载删除。
+ |
+
+外部存储
+ |
+internal://share/
+ |
+所有应用可见
+ |
+随应用卸载删除。其他应用在有相应权限的情况下可读写此目录下的文件。
+ |
+
+
+
+
+### 使用说明
+
+当前分布式文件子系统所提供的 IO 接口,按照编程模型,可划分为如下几种类型:
+
+- 同步编程模型
+
+ 名称包含 Sync 的接口实现为同步模型。用户在调用这些接口的时候,将同步等待,直至执行完成,执行结果以函数返回值的形式返回。
+
+ 下例以只读的方式打开一个文件流,接着试图读取其中前 4096 个字节并将之转换为 UTF-8 编码的字符串,最后关闭该文件流。
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ var ss = fileio.Stream.createStreamSync("tmp", "r")
+ buf = new ArrayBuffer(4096)
+ ss.readSync(buf)
+ console.log(String.fromCharCode.apply(null, new Uint8Array(buf)))
+ ss.closeSync()
+ }
+ catch (e) {
+ console.log(e);
+ }
+ ```
+
+
+- 异步编程模型:Promise
+
+ @OHOS.distributedfile.fileio 模块中,名称不含 Sync 的接口,在不提供最后一个函数型参数 callback 的时候,即实现为 Promsie 异步模型。Promise 异步模型是 OHOS 标准异步模型之一。用户在调用这些接口的时候,接口实现将异步执行任务,同时返回一个 promise 对象,其代表异步操作的结果。在返回的结果的个数超过一个时,其以对象属性的形式返回。
+
+ 下例通过 Promise 链依次完成:以只读方式打开文件流、尝试读取文件前 4096 个字节、显示读取内容的长度,最后关闭文件。
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ let openedStream
+ fileio.Stream.createStream("test.txt", "r")
+ .then(function (ss) {
+ openedStream = ss;
+ return ss.read(new ArrayBuffer(4096))
+ })
+ .then(function (res) {
+ console.log(res.bytesRead);
+ console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer)))
+ return openedStream.close()
+ })
+ .then(function (undefined) {
+ console.log("Stream is closed")
+ })
+ .catch(function (e) {
+ console.log(e)
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- 异步编程模型:Callback
+
+ @OHOS.distributedfile.fileio 模块中,名字不含 Sync 的接口,在提供最后一个函数性参数 callback 的时候,即实现为 Callback 异步模型。Callback 异步模型是 OHOS 标准异步模型之一。用户在调用这些接口的时候,接口实现将异步执行任务。任务执行结果以参数的形式提供给用户注册的回调函数。这些参数的第一个是 Error 或 undefined 类型,分别表示执行出错与正常。
+
+ 下例异步创建文件流,并在文件流的回调函数中异步读取文件的前 4096 字节,接着在读取文件的回调函数中异步关闭文件。
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) {
+ if (!err) {
+ ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) {
+ if (!err) {
+ console.log('readLen: ' + readLen)
+ console.log('data: ' + String.fromCharCode.apply(null, new Uint8Array(buf)))
+ } else {
+ console.log('Cannot read from the stream ' + err)
+ }
+ ss.close(function (err) {
+ console.log(`Stream is ${err ? 'not' : ''}closed`)
+ });
+ })
+ } else {
+ console.log('Cannot open the stream ' + err)
+ }
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- 异步编程模型:Legacy
+
+ @system.file 模块中的所有接口都实现为 Legacy 异步模型。用户在调用这些接口的时候,需要提供 success、fail 及 complete 三个回调。在正确提供参数的情况下,当异步任务完成后,接口会根据是否成功,分别调用 success 回调或 fail 回调,并最终调用 complete 回调。
+
+ 下例异步判断 URI 所指向的文件是否存在,并相应提供三个回调用于打印判断结果。
+
+ ```
+ import file from '@system.file'
+
+ file.access({
+ uri: 'internal://app/test.txt',
+ success: function() {
+ console.log('call access success.');
+ },
+ fail: function(data, code) {
+ console.error('call fail callback fail, code: ' + code + ', data: ' + data);
+ },
+ complete: function () {
+ console.log('call access finally.');
+ }
+ });
+
+ console.log("file access tested done")
+ ```
+
+
+## 相关仓
+
+**分布式文件**
-### 接口说明
+distributeddatamgr_distributedfile
-[statfs接口](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/reference/apis/js-apis-statfs.md)
diff --git a/bundle.json b/bundle.json
new file mode 100644
index 0000000000000000000000000000000000000000..65ff5c02e3e49bdf036b8f8428828463fab09633
--- /dev/null
+++ b/bundle.json
@@ -0,0 +1,43 @@
+{
+ "name": "file_api",
+ "description": "provides the application with JS interfaces for IO",
+ "version": "3.1",
+ "license": "Apache License 2.0",
+ "publishAs": "code-segment",
+ "segment": {
+ "destPath": "foundation/filemanagement/file_api"
+ },
+ "dirs": {},
+ "scripts": {},
+ "component": {
+ "name": "file_api",
+ "subsystem": "filemanagement",
+ "syscap": [],
+ "features": [],
+ "adapted_system_type": ["standard"],
+ "rom": "",
+ "ram": "",
+ "deps": {
+ "components": [
+ "ability_base",
+ "ability_manager",
+ "appexecfwk_base",
+ "appexecfwk_core",
+ "want",
+ "libhilog",
+ "ipc_core",
+ "ace_napi",
+ "samgr_proxy"
+ ],
+ "third_party": [
+ "e2fsprogs"
+ ]
+ },
+ "build": {
+ "sub_component": [
+ "//foundation/filemanagement/file_api/interfaces/kits/js:build_kits_js",
+ "//third_party/e2fsprogs:e2fsprogs"
+ ]
+ }
+ }
+ }
\ No newline at end of file
diff --git a/figures/distributed-file-subsystem-architecture.png b/figures/distributed-file-subsystem-architecture.png
new file mode 100644
index 0000000000000000000000000000000000000000..d36a4b1bca8f27ebe38b448dc6169de767811d27
Binary files /dev/null and b/figures/distributed-file-subsystem-architecture.png differ
diff --git "a/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png"
new file mode 100644
index 0000000000000000000000000000000000000000..e3763b766aff5cf1c80c31a0ea17c527a9f70a8f
Binary files /dev/null and "b/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" differ
diff --git a/file_api_aafwk.gni b/file_api_aafwk.gni
new file mode 100644
index 0000000000000000000000000000000000000000..36d78c22cc8c87aef866c493fdb69951b4045cc5
--- /dev/null
+++ b/file_api_aafwk.gni
@@ -0,0 +1,15 @@
+# Copyright (c) 2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+aafwk_kits_path = "//foundation/ability/ability_runtime/frameworks/kits"
+aafwk_path = "//foundation/ability/ability_runtime"
diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..9b02240db3474290ed455ddc4c24785165826bc6
--- /dev/null
+++ b/interfaces/kits/js/BUILD.gn
@@ -0,0 +1,247 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//foundation/filemanagement/file_api/file_api_aafwk.gni")
+
+file_common_src = [
+ "src/common/file_helper/fd_guard.cpp",
+ "src/common/napi/n_async/n_async_work_callback.cpp",
+ "src/common/napi/n_async/n_async_work_promise.cpp",
+ "src/common/napi/n_async/n_ref.cpp",
+ "src/common/napi/n_class.cpp",
+ "src/common/napi/n_func_arg.cpp",
+ "src/common/napi/n_val.cpp",
+ "src/common/uni_error.cpp",
+]
+
+ohos_shared_library("fileio") {
+ subsystem_name = "filemanagement"
+ part_name = "file_api"
+
+ relative_install_dir = "module"
+
+ include_dirs = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//third_party/bounds_checking_function/include",
+ "//third_party/libuv/include",
+ "//third_party/openssl/include",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/file_helper",
+ ]
+
+ sources = file_common_src
+ sources += [
+ "src/common/file_helper/hash_file.cpp",
+ "src/mod_fileio/class_constants/constants.cpp",
+ "src/mod_fileio/class_dir/dir_n_exporter.cpp",
+ "src/mod_fileio/class_dirent/dirent_n_exporter.cpp",
+ "src/mod_fileio/class_stat/stat_n_exporter.cpp",
+ "src/mod_fileio/class_stream/flush.cpp",
+ "src/mod_fileio/class_stream/stream_n_exporter.cpp",
+ "src/mod_fileio/class_watcher/watcher_n_exporter.cpp",
+ "src/mod_fileio/common_func.cpp",
+ "src/mod_fileio/module.cpp",
+ "src/mod_fileio/properties/chmod.cpp",
+ "src/mod_fileio/properties/chown.cpp",
+ "src/mod_fileio/properties/close.cpp",
+ "src/mod_fileio/properties/copy_file.cpp",
+ "src/mod_fileio/properties/create_stream.cpp",
+ "src/mod_fileio/properties/fchmod.cpp",
+ "src/mod_fileio/properties/fchown.cpp",
+ "src/mod_fileio/properties/fdatasync.cpp",
+ "src/mod_fileio/properties/fdopen_stream.cpp",
+ "src/mod_fileio/properties/fstat.cpp",
+ "src/mod_fileio/properties/fsync.cpp",
+ "src/mod_fileio/properties/ftruncate.cpp",
+ "src/mod_fileio/properties/hash.cpp",
+ "src/mod_fileio/properties/lchown.cpp",
+ "src/mod_fileio/properties/link.cpp",
+ "src/mod_fileio/properties/lseek.cpp",
+ "src/mod_fileio/properties/lstat.cpp",
+ "src/mod_fileio/properties/mkdtemp.cpp",
+ "src/mod_fileio/properties/open.cpp",
+ "src/mod_fileio/properties/open_dir.cpp",
+ "src/mod_fileio/properties/posix_fallocate.cpp",
+ "src/mod_fileio/properties/prop_n_exporter.cpp",
+ "src/mod_fileio/properties/read_text.cpp",
+ "src/mod_fileio/properties/rename.cpp",
+ "src/mod_fileio/properties/rmdir.cpp",
+ "src/mod_fileio/properties/stat.cpp",
+ "src/mod_fileio/properties/symlink.cpp",
+ "src/mod_fileio/properties/truncate.cpp",
+ "src/mod_fileio/properties/watcher.cpp",
+ ]
+
+ deps = [
+ "//foundation/arkui/napi:ace_napi",
+ "//third_party/bounds_checking_function:libsec_static",
+ "//third_party/openssl:libcrypto_static",
+ ]
+
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+}
+
+ohos_shared_library("file") {
+ subsystem_name = "filemanagement"
+ part_name = "file_api"
+
+ relative_install_dir = "module"
+
+ include_dirs = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//third_party/bounds_checking_function/include",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/file_helper",
+ ]
+
+ sources = file_common_src
+ sources += [
+ "src/common/ability_helper.cpp",
+ "src/mod_file/class_file/file_n_exporter.cpp",
+ "src/mod_file/common_func.cpp",
+ "src/mod_file/module.cpp",
+ ]
+
+ deps = [
+ "${aafwk_kits_path}/ability/native:abilitykit_native",
+ "//foundation/arkui/napi:ace_napi",
+ "//third_party/bounds_checking_function:libsec_static",
+ ]
+
+ external_deps = [
+ "ability_base:want",
+ "ability_runtime:ability_manager",
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "eventhandler:libeventhandler",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ ]
+}
+
+ohos_shared_library("statfs") {
+ subsystem_name = "filemanagement"
+ part_name = "file_api"
+
+ relative_install_dir = "module"
+
+ sources = [
+ "src/mod_statfs/statfs_n_exporter.cpp",
+ "src/mod_statfs/statfs_napi.cpp",
+ ]
+
+ deps = [
+ "//foundation/filemanagement/file_api/utils/filemgmt_libhilog",
+ "//foundation/filemanagement/file_api/utils/filemgmt_libn",
+ ]
+
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+}
+
+ohos_shared_library("environment") {
+ subsystem_name = "filemanagement"
+ part_name = "file_api"
+
+ relative_install_dir = "module"
+
+ include_dirs = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ ]
+
+ sources = [
+ "src/common/napi/n_async/n_async_work_callback.cpp",
+ "src/common/napi/n_async/n_async_work_promise.cpp",
+ "src/common/napi/n_async/n_ref.cpp",
+ "src/common/napi/n_func_arg.cpp",
+ "src/common/napi/n_val.cpp",
+ "src/common/uni_error.cpp",
+ "src/mod_environment/environment_n_exporter.cpp",
+ "src/mod_environment/environment_napi.cpp",
+ ]
+
+ deps = [ "//foundation/arkui/napi:ace_napi" ]
+
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+}
+
+ohos_shared_library("securitylabel") {
+ subsystem_name = "filemanagement"
+ part_name = "file_api"
+
+ relative_install_dir = "module"
+
+ cflags = [ "-Wno-format" ]
+
+ include_dirs = [
+ "//foundation/arkui/napi/interfaces/kits",
+ "//foundation/arkui/ace_engine/frameworks/base/utils",
+ "//foundation/arkui/ace_engine/frameworks",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ ]
+
+ sources = file_common_src
+ sources += [
+ "src/mod_securitylabel/securitylabel_n_exporter.cpp",
+ "src/mod_securitylabel/securitylabel_napi.cpp",
+ ]
+
+ deps = [ "//foundation/arkui/napi:ace_napi" ]
+
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+}
+
+ohos_shared_library("document") {
+ subsystem_name = "filemanagement"
+ part_name = "file_api"
+
+ relative_install_dir = "module"
+
+ include_dirs = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ ]
+
+ sources = [
+ "src/common/napi/n_async/n_async_work_callback.cpp",
+ "src/common/napi/n_async/n_async_work_promise.cpp",
+ "src/common/napi/n_async/n_ref.cpp",
+ "src/common/napi/n_func_arg.cpp",
+ "src/common/napi/n_val.cpp",
+ "src/common/uni_error.cpp",
+ "src/mod_document/document_n_exporter.cpp",
+ "src/mod_document/document_napi.cpp",
+ ]
+
+ deps = [ "//foundation/arkui/napi:ace_napi" ]
+
+ external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
+}
+
+group("build_kits_js") {
+ deps = [
+ ":document",
+ ":environment",
+ ":file",
+ ":fileio",
+ ":securitylabel",
+ ":statfs",
+ ]
+}
diff --git a/interfaces/kits/js/src/common/ability_helper.cpp b/interfaces/kits/js/src/common/ability_helper.cpp
index c5aae1548bf0240a16147f25ad208ca7700a55fa..595bee685037846a54b02689bddf6258866b4675 100644
--- a/interfaces/kits/js/src/common/ability_helper.cpp
+++ b/interfaces/kits/js/src/common/ability_helper.cpp
@@ -29,7 +29,7 @@ Ability* AbilityHelper::GetJsAbility(napi_env env)
{
napi_value global = nullptr;
napi_value abilityContext = nullptr;
-
+
napi_status status = napi_get_global(env, &global);
if (status != napi_ok || global == nullptr) {
HILOGE("Cannot get global instance for %{public}d", status);
diff --git a/interfaces/kits/js/src/common/ability_helper.h b/interfaces/kits/js/src/common/ability_helper.h
index e998027c021b5d2d21cdbab1558a4718d100b888..36c69cb77ea8bd958c2c46b5f32a4894e853f43e 100644
--- a/interfaces/kits/js/src/common/ability_helper.h
+++ b/interfaces/kits/js/src/common/ability_helper.h
@@ -13,9 +13,9 @@
* limitations under the License.
*/
-#pragma once
+#ifndef INTERFACES_KITS_NAPI_COMMON_ABILITY_HELPER_H
+#define INTERFACES_KITS_NAPI_COMMON_ABILITY_HELPER_H
-#include "../common/napi/uni_header.h"
#include "ability.h"
namespace OHOS {
@@ -24,4 +24,5 @@ struct AbilityHelper {
static AppExecFwk::Ability *GetJsAbility(napi_env env);
};
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/file_helper/fd_guard.cpp b/interfaces/kits/js/src/common/file_helper/fd_guard.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6959b45a52f534f468561ff090199b2e3c5f8735
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/fd_guard.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fd_guard.h"
+
+#include
+
+#include "../log.h"
+
+namespace OHOS {
+namespace DistributedFS {
+FDGuard::FDGuard(int fd) : fd_(fd) {}
+
+FDGuard::FDGuard(int fd, bool autoClose) : fd_(fd), autoClose_(autoClose) {}
+
+FDGuard::FDGuard(FDGuard &&fdg) : fd_(fdg.fd_), autoClose_(fdg.autoClose_)
+{
+ fdg.fd_ = -1;
+}
+
+FDGuard &FDGuard::operator=(FDGuard &&fdg)
+{
+ if (this == &fdg) {
+ return *this;
+ }
+ this->fd_ = fdg.fd_;
+ this->autoClose_ = fdg.autoClose_;
+ fdg.fd_ = -1;
+ return *this;
+}
+
+FDGuard::~FDGuard()
+{
+ if (fd_ >= 0 && fd_ <= STDERR_FILENO) {
+ HILOGI("~FDGuard, fd_ = %{public}d", fd_);
+ }
+ if (fd_ >= 0 && autoClose_) {
+ close(fd_);
+ }
+}
+
+FDGuard::operator bool() const
+{
+ return fd_ >= 0;
+}
+
+int FDGuard::GetFD() const
+{
+ return fd_;
+}
+
+void FDGuard::SetFD(int fd, bool autoClose)
+{
+ fd_ = fd;
+ autoClose_ = autoClose;
+}
+
+void FDGuard::ClearFD()
+{
+ fd_ = -1;
+}
+} // namespace DistributedFS
+} // namespace OHOS
diff --git a/interfaces/kits/js/src/common/file_helper/fd_guard.h b/interfaces/kits/js/src/common/file_helper/fd_guard.h
new file mode 100644
index 0000000000000000000000000000000000000000..07c27b19d46a21d9e11eb999877be70306671699
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/fd_guard.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FD_GUARD_H
+#define FD_GUARD_H
+
+namespace OHOS {
+namespace DistributedFS {
+class FDGuard final {
+public:
+ FDGuard() = default;
+ explicit FDGuard(int fd);
+ FDGuard(int fd, bool autoClose);
+
+ FDGuard(const FDGuard &fdg) = delete;
+ FDGuard &operator=(const FDGuard &fdg) = delete;
+
+ FDGuard(FDGuard &&fdg);
+ FDGuard &operator=(FDGuard &&fdg);
+
+ operator bool() const;
+
+ ~FDGuard();
+
+ int GetFD() const;
+ void SetFD(int fd, bool autoClose = true);
+ void ClearFD();
+
+private:
+ int fd_ = -1;
+ bool autoClose_ = true;
+};
+} // namespace DistributedFS
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/file_helper/hash_file.cpp b/interfaces/kits/js/src/common/file_helper/hash_file.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..2bd54cc657cafbf6dbb1c3bb026eee2b118a118a
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/hash_file.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "hash_file.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace DistributedFS {
+using namespace std;
+
+static tuple HashFinal(int err, const unique_ptr &hashBuf, size_t hashLen)
+{
+ if (err) {
+ return { err, "" };
+ }
+
+ stringstream ss;
+ for (size_t i = 0; i < hashLen; ++i) {
+ const int hexPerByte = 2;
+ ss << std::uppercase << std::setfill('0') << std::setw(hexPerByte) << std::hex <<
+ static_cast(hashBuf[i]);
+ }
+
+ return { err, ss.str() };
+}
+
+static int ForEachFileSegment(const string &fpath, function executor)
+{
+ unique_ptr filp = { fopen(fpath.c_str(), "r"), fclose };
+ if (!filp) {
+ return errno;
+ }
+
+ const size_t pageSize { getpagesize() };
+ auto buf = make_unique(pageSize);
+ size_t actLen;
+ do {
+ actLen = fread(buf.get(), 1, pageSize, filp.get());
+ if (actLen > 0) {
+ executor(buf.get(), actLen);
+ }
+ } while (actLen == pageSize);
+
+ return ferror(filp.get()) ? errno : 0;
+}
+
+tuple HashFile::HashWithMD5(const string &fpath)
+{
+ auto res = make_unique(MD5_DIGEST_LENGTH);
+ MD5_CTX ctx;
+ MD5_Init(&ctx);
+ auto md5Update = [ctx = &ctx](char *buf, size_t len) {
+ MD5_Update(ctx, buf, len);
+ };
+ int err = ForEachFileSegment(fpath, md5Update);
+ MD5_Final(res.get(), &ctx);
+ return HashFinal(err, res, MD5_DIGEST_LENGTH);
+}
+
+tuple HashFile::HashWithSHA1(const string &fpath)
+{
+ auto res = make_unique(SHA_DIGEST_LENGTH);
+ SHA_CTX ctx;
+ SHA1_Init(&ctx);
+ auto sha1Update = [ctx = &ctx](char *buf, size_t len) {
+ SHA1_Update(ctx, buf, len);
+ };
+ int err = ForEachFileSegment(fpath, sha1Update);
+ SHA1_Final(res.get(), &ctx);
+ return HashFinal(err, res, SHA_DIGEST_LENGTH);
+}
+
+tuple HashFile::HashWithSHA256(const string &fpath)
+{
+ auto res = make_unique(SHA256_DIGEST_LENGTH);
+ SHA256_CTX ctx;
+ SHA256_Init(&ctx);
+ auto sha256Update = [ctx = &ctx](char *buf, size_t len) {
+ SHA256_Update(ctx, buf, len);
+ };
+ int err = ForEachFileSegment(fpath, sha256Update);
+ SHA256_Final(res.get(), &ctx);
+ return HashFinal(err, res, SHA256_DIGEST_LENGTH);
+}
+} // namespace DistributedFS
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/file_helper/hash_file.h b/interfaces/kits/js/src/common/file_helper/hash_file.h
new file mode 100644
index 0000000000000000000000000000000000000000..81d68a2e4c3e1a3028c7569785706f97c9db02dc
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/hash_file.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HASH_FILE_H
+#define HASH_FILE_H
+
+#include
+#include
+
+namespace OHOS {
+namespace DistributedFS {
+class HashFile {
+public:
+ static std::tuple HashWithMD5(const std::string &fpath);
+ static std::tuple HashWithSHA1(const std::string &fpath);
+ static std::tuple HashWithSHA256(const std::string &fpath);
+};
+} // namespace DistributedFS
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/log.h b/interfaces/kits/js/src/common/log.h
index 32a09a751f6885a9ddca0cddfe3b31df3dc0ee21..412b5f6cf15ac22e2b441e570ef4495cf65388f9 100644
--- a/interfaces/kits/js/src/common/log.h
+++ b/interfaces/kits/js/src/common/log.h
@@ -13,19 +13,20 @@
* limitations under the License.
*/
-#pragma once
+#ifndef INTERFACES_KITS_NAPI_COMMON_LOG_H
+#define INTERFACES_KITS_NAPI_COMMON_LOG_H
#include
#include
#include
-#ifndef FILE_SUBSYSTEM_DEV_ON_PC
+#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL
#include "hilog/log.h"
#endif
namespace OHOS {
namespace DistributedFS {
-#ifndef FILE_SUBSYSTEM_DEV_ON_PC
+#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL
static constexpr int FILEIO_DOMAIN_ID = 0;
static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_DOMAIN_ID, "distributedfilejs" };
@@ -77,7 +78,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_D
} \
str____ += "\n"; \
printf(str____.c_str(), ##__VA_ARGS__); \
- } while (0);
+ } while (0) \
#define HILOGD(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
#define HILOGI(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
@@ -87,4 +88,5 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_D
#endif
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h b/interfaces/kits/js/src/common/napi/n_async/n_async_context.h
index 7c45ce20a60e0377caef091ef15b9794b6b0ff7c..87339bbdddfdc837b658e60e7026f2bc10e6bdc7 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_context.h
@@ -16,8 +16,6 @@
#ifndef N_ASYNC_CONTEXT_H
#define N_ASYNC_CONTEXT_H
-#include
-
#include "../../uni_error.h"
#include "../n_val.h"
#include "n_ref.h"
@@ -43,7 +41,7 @@ public:
class NAsyncContextPromise : public NAsyncContext {
public:
- napi_deferred deferred_;
+ napi_deferred deferred_ = nullptr;
explicit NAsyncContextPromise(NVal thisPtr) : NAsyncContext(thisPtr) {}
~NAsyncContextPromise() = default;
};
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp
index 6b6d0b70a6fd54e7c9193d4867600aae41e70759..8c3af6149c68a3270987cb6e9c7c15710bcc1d2a 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp
@@ -69,7 +69,7 @@ static void CallbackComplete(napi_env env, napi_status status, void *data)
NVal NAsyncWorkCallback::Schedule(string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete)
{
if (!ctx_->cb_ || !ctx_->cb_.Deref(env_).TypeIs(napi_function)) {
- UniError(EINVAL).ThrowErr(env_, "The callback shall be a funciton");
+ UniError(EINVAL).ThrowErr(env_, "The callback shall be a function");
return NVal();
}
@@ -91,7 +91,7 @@ NVal NAsyncWorkCallback::Schedule(string procedureName, NContextCBExec cbExec, N
return NVal();
}
- ctx_ = nullptr; // The ownership of ctx_ has been transfered
+ ctx_ = nullptr; // The ownership of ctx_ has been transferred
return NVal::CreateUndefined(env_);
}
} // namespace DistributedFS
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h
index 7b7f190c8f45636fdded6b81871ce5487bd30535..9bc6d5f3d7b7125e50fda9baedb4d70f2b397003 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h
@@ -26,7 +26,7 @@ public:
~NAsyncWorkCallback() = default;
NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final;
- NAsyncWorkCallback(const NAsyncWorkCallback&) = delete;
+
private:
NAsyncContextCallback *ctx_ = nullptr;
};
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp
index 3809c1a4b0255236ceb8dadfb3d05c77b67366d9..f0ef6df4985a4e6b7b6618d3c917179c66625f7d 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp
@@ -84,7 +84,7 @@ NVal NAsyncWorkPromise::Schedule(string procedureName, NContextCBExec cbExec, NC
return NVal();
}
- ctx_ = nullptr; // The ownership of ctx_ has been transfered
+ ctx_ = nullptr; // The ownership of ctx_ has been transferred
return { env_, result };
}
} // namespace DistributedFS
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h
index f2406913f1262b79307cf12091f494c2375e104e..8a049de65e913edaeb99a297acefacf6a1a6d4a0 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h
@@ -26,7 +26,7 @@ public:
~NAsyncWorkPromise() = default;
NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final;
- NAsyncWorkPromise(const NAsyncWorkPromise&) = delete;
+
private:
NAsyncContextPromise *ctx_;
};
diff --git a/interfaces/kits/js/src/common/napi/n_class.cpp b/interfaces/kits/js/src/common/napi/n_class.cpp
index 0e9028b02e2bca7e956fe993da40425a34bbac84..dbda702d0e8dd2849d9ea5515138cd78b95e3faf 100644
--- a/interfaces/kits/js/src/common/napi/n_class.cpp
+++ b/interfaces/kits/js/src/common/napi/n_class.cpp
@@ -25,7 +25,7 @@ namespace DistributedFS {
using namespace std;
NClass &NClass::GetInstance()
{
- static NClass nClass;
+ static thread_local NClass nClass;
return nClass;
}
@@ -69,7 +69,7 @@ bool NClass::SaveClass(napi_env env, string className, napi_value exClass)
return res == napi_ok;
}
-napi_value NClass::InstantiateClass(napi_env env, string className, vector args)
+napi_value NClass::InstantiateClass(napi_env env, const string& className, const vector& args)
{
NClass &nClass = NClass::GetInstance();
lock_guard(nClass.exClassMapLock);
@@ -96,4 +96,4 @@ napi_value NClass::InstantiateClass(napi_env env, string className, vector
-#include
-#include
-#include
-#include
-#include
#include "../log.h"
@@ -39,7 +35,7 @@ public:
napi_callback constructor,
std::vector &&properties);
static bool SaveClass(napi_env env, std::string className, napi_value exClass);
- static napi_value InstantiateClass(napi_env env, std::string className, std::vector args);
+ static napi_value InstantiateClass(napi_env env, const std::string& className, const std::vector& args);
template static T *GetEntityOf(napi_env env, napi_value objStat)
{
@@ -79,4 +75,5 @@ private:
std::mutex exClassMapLock;
};
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/napi/n_exporter.h b/interfaces/kits/js/src/common/napi/n_exporter.h
index 2ade0c076d11ed9f64b8d578f9a11d34241210a8..db5563f7be0153dfe4a00442736cac102a81b21c 100644
--- a/interfaces/kits/js/src/common/napi/n_exporter.h
+++ b/interfaces/kits/js/src/common/napi/n_exporter.h
@@ -13,12 +13,8 @@
* limitations under the License.
*/
-#pragma once
-
-#include "uni_header.h"
-
-#include
-#include
+#ifndef INTERFACES_KITS_NAPI_COMMON_NAPI_N_EXPORTER_H
+#define INTERFACES_KITS_NAPI_COMMON_NAPI_N_EXPORTER_H
#include "n_val.h"
@@ -36,4 +32,5 @@ protected:
NVal exports_;
};
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/napi/n_func_arg.cpp b/interfaces/kits/js/src/common/napi/n_func_arg.cpp
index 123ef8d0ab67ee1bcbe2e3149f2eab6935c9d45e..1a3d6d8dd0058ac6f9590d40a638f823002aa14d 100644
--- a/interfaces/kits/js/src/common/napi/n_func_arg.cpp
+++ b/interfaces/kits/js/src/common/napi/n_func_arg.cpp
@@ -15,11 +15,7 @@
#include "n_func_arg.h"
-#include
-#include
-
#include "../log.h"
-#include "../uni_error.h"
namespace OHOS {
namespace DistributedFS {
@@ -33,6 +29,7 @@ void NFuncArg::SetArgc(size_t argc)
{
argc_ = argc;
}
+
void NFuncArg::SetThisVar(napi_value thisVar)
{
thisVar_ = thisVar;
diff --git a/interfaces/kits/js/src/common/napi/n_func_arg.h b/interfaces/kits/js/src/common/napi/n_func_arg.h
index 7ff5b29425721764591f7d706909fed35e117963..e0d2a17dec0240a3e79f7cb6d41b74f018fce470 100644
--- a/interfaces/kits/js/src/common/napi/n_func_arg.h
+++ b/interfaces/kits/js/src/common/napi/n_func_arg.h
@@ -13,14 +13,9 @@
* limitations under the License.
*/
-#pragma once
+#ifndef INTERFACES_KITS_NAPI_COMMON_NAPI_N_FUNC_ARG_H
+#define INTERFACES_KITS_NAPI_COMMON_NAPI_N_FUNC_ARG_H
-#include
-#include