• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "prop_n_exporter.h"
17 
18 #include <cstring>
19 #include <ctime>
20 #include <iostream>
21 #include <memory>
22 #include <sstream>
23 #include <unistd.h>
24 
25 #include "common_func.h"
26 #include "class_file/file_entity.h"
27 #include "class_file/file_n_exporter.h"
28 #include "close.h"
29 #include "fdatasync.h"
30 #include "file_utils.h"
31 #include "filemgmt_libn.h"
32 #include "fsync.h"
33 #include "js_native_api.h"
34 #include "js_native_api_types.h"
35 #include "lstat.h"
36 #include "mkdtemp.h"
37 #include "open.h"
38 #include "rename.h"
39 #include "rmdirent.h"
40 #include "stat.h"
41 #include "truncate.h"
42 
43 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM)
44 #include "copy_file.h"
45 #include "copydir.h"
46 #include "create_randomaccessfile.h"
47 #include "create_stream.h"
48 #include "dup.h"
49 #include "fdopen_stream.h"
50 #include "listfile.h"
51 #include "move.h"
52 #include "movedir.h"
53 #include "read_text.h"
54 #include "symlink.h"
55 #include "watcher.h"
56 #endif
57 
58 namespace OHOS {
59 namespace FileManagement {
60 namespace ModuleFileIO {
61 using namespace std;
62 using namespace OHOS::FileManagement::LibN;
63 
AccessSync(napi_env env,napi_callback_info info)64 napi_value PropNExporter::AccessSync(napi_env env, napi_callback_info info)
65 {
66     NFuncArg funcArg(env, info);
67     if (!funcArg.InitArgs(NARG_CNT::ONE)) {
68         HILOGE("Number of arguments unmatched");
69         NError(EINVAL).ThrowErr(env);
70         return nullptr;
71     }
72 
73     auto [succ, path, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
74     if (!succ) {
75         HILOGE("Invalid path from JS first argument");
76         NError(EINVAL).ThrowErr(env);
77         return nullptr;
78     }
79 
80     bool isAccess = false;
81     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> access_req = {
82         new uv_fs_t, CommonFunc::fs_req_cleanup };
83     if (!access_req) {
84         HILOGE("Failed to request heap memory.");
85         NError(ENOMEM).ThrowErr(env);
86         return nullptr;
87     }
88     int ret = uv_fs_access(nullptr, access_req.get(), path.get(), 0, nullptr);
89     if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) {
90         HILOGE("Failed to access file by path");
91         NError(ret).ThrowErr(env);
92         return nullptr;
93     }
94     if (ret == 0) {
95         isAccess = true;
96     }
97     return NVal::CreateBool(env, isAccess).val_;
98 }
99 
Access(napi_env env,napi_callback_info info)100 napi_value PropNExporter::Access(napi_env env, napi_callback_info info)
101 {
102     NFuncArg funcArg(env, info);
103     if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
104         HILOGE("Number of arguments unmatched");
105         NError(EINVAL).ThrowErr(env);
106         return nullptr;
107     }
108 
109     auto [succ, tmp, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
110     if (!succ) {
111         HILOGE("Invalid path from JS first argument");
112         NError(EINVAL).ThrowErr(env);
113         return nullptr;
114     }
115 
116     auto result = CreateSharedPtr<AsyncAccessArg>();
117     if (result == nullptr) {
118         HILOGE("Failed to request heap memory.");
119         NError(ENOMEM).ThrowErr(env);
120         return nullptr;
121     }
122     auto cbExec = [path = string(tmp.get()), result]() -> NError {
123         std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> access_req = {
124             new uv_fs_t, CommonFunc::fs_req_cleanup };
125         if (!access_req) {
126             HILOGE("Failed to request heap memory.");
127             return NError(ENOMEM);
128         }
129         int ret = uv_fs_access(nullptr, access_req.get(), path.c_str(), 0, nullptr);
130         if (ret == 0) {
131             result->isAccess = true;
132         }
133         return (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) ? NError(ret) : NError(ERRNO_NOERR);
134     };
135 
136     auto cbComplete = [result](napi_env env, NError err) -> NVal {
137         if (err) {
138             return { env, err.GetNapiErr(env) };
139         }
140         return NVal::CreateBool(env, result->isAccess);
141     };
142 
143     NVal thisVar(env, funcArg.GetThisVar());
144     if (funcArg.GetArgc() == NARG_CNT::ONE) {
145         return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_ACCESS_NAME, cbExec, cbComplete).val_;
146     } else {
147         NVal cb(env, funcArg[NARG_POS::SECOND]);
148         return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_ACCESS_NAME, cbExec, cbComplete).val_;
149     }
150 }
151 
Unlink(napi_env env,napi_callback_info info)152 napi_value PropNExporter::Unlink(napi_env env, napi_callback_info info)
153 {
154     NFuncArg funcArg(env, info);
155     if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
156         HILOGE("Number of Arguments Unmatched");
157         NError(EINVAL).ThrowErr(env);
158         return nullptr;
159     }
160 
161     auto [succ, tmp, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
162     if (!succ) {
163         HILOGE("Invalid path from JS first argument");
164         NError(EINVAL).ThrowErr(env);
165         return nullptr;
166     }
167 
168     auto cbExec = [path = string(tmp.get())]() -> NError {
169         std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> unlink_req = {
170             new uv_fs_t, CommonFunc::fs_req_cleanup };
171         if (!unlink_req) {
172             HILOGE("Failed to request heap memory.");
173             return NError(ENOMEM);
174         }
175         int ret = uv_fs_unlink(nullptr, unlink_req.get(), path.c_str(), nullptr);
176         if (ret < 0) {
177             HILOGE("Failed to unlink with path");
178             return NError(ret);
179         }
180         return NError(ERRNO_NOERR);
181     };
182 
183     auto cbCompl = [](napi_env env, NError err) -> NVal {
184         if (err) {
185             return { env, err.GetNapiErr(env) };
186         }
187         return { NVal::CreateUndefined(env) };
188     };
189 
190     NVal thisVar(env, funcArg.GetThisVar());
191     if (funcArg.GetArgc() == NARG_CNT::ONE) {
192         return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_UNLINK_NAME, cbExec, cbCompl).val_;
193     } else {
194         NVal cb(env, funcArg[NARG_POS::SECOND]);
195         return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_UNLINK_NAME, cbExec, cbCompl).val_;
196     }
197 }
198 
UnlinkSync(napi_env env,napi_callback_info info)199 napi_value PropNExporter::UnlinkSync(napi_env env, napi_callback_info info)
200 {
201     NFuncArg funcArg(env, info);
202     if (!funcArg.InitArgs(NARG_CNT::ONE)) {
203         HILOGE("Number of arguments unmatched");
204         NError(EINVAL).ThrowErr(env);
205         return nullptr;
206     }
207 
208     auto [succ, path, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
209     if (!succ) {
210         HILOGE("Invalid path from JS first argument");
211         NError(EINVAL).ThrowErr(env);
212         return nullptr;
213     }
214 
215     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> unlink_req = {
216         new uv_fs_t, CommonFunc::fs_req_cleanup };
217     if (!unlink_req) {
218         HILOGE("Failed to request heap memory.");
219         NError(ENOMEM).ThrowErr(env);
220         return nullptr;
221     }
222     int ret = uv_fs_unlink(nullptr, unlink_req.get(), path.get(), nullptr);
223     if (ret < 0) {
224         HILOGE("Failed to unlink with path");
225         NError(ret).ThrowErr(env);
226         return nullptr;
227     }
228 
229     return NVal::CreateUndefined(env).val_;
230 }
231 
Mkdir(napi_env env,napi_callback_info info)232 napi_value PropNExporter::Mkdir(napi_env env, napi_callback_info info)
233 {
234     NFuncArg funcArg(env, info);
235     if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
236         HILOGE("Number of arguments unmatched");
237         NError(EINVAL).ThrowErr(env);
238         return nullptr;
239     }
240 
241     auto [succ, tmp, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
242     if (!succ) {
243         HILOGE("Invalid path from JS first argument");
244         NError(EINVAL).ThrowErr(env);
245         return nullptr;
246     }
247 
248     auto cbExec = [path = string(tmp.get())]() -> NError {
249         std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> mkdir_req = {
250             new uv_fs_t, CommonFunc::fs_req_cleanup };
251         if (!mkdir_req) {
252             HILOGE("Failed to request heap memory.");
253             return NError(ENOMEM);
254         }
255         int ret = uv_fs_mkdir(nullptr, mkdir_req.get(), path.c_str(), DIR_DEFAULT_PERM, nullptr);
256         if (ret < 0) {
257             HILOGE("Failed to create directory");
258             return NError(ret);
259         }
260         return NError(ERRNO_NOERR);
261     };
262 
263     auto cbCompl = [](napi_env env, NError err) -> NVal {
264         if (err) {
265             return { env, err.GetNapiErr(env) };
266         }
267         return { NVal::CreateUndefined(env) };
268     };
269 
270     NVal thisVar(env, funcArg.GetThisVar());
271     if (funcArg.GetArgc() == NARG_CNT::ONE) {
272         return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_MKDIR_NAME, cbExec, cbCompl).val_;
273     } else {
274         NVal cb(env, funcArg[NARG_POS::SECOND]);
275         return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_MKDIR_NAME, cbExec, cbCompl).val_;
276     }
277 }
278 
MkdirSync(napi_env env,napi_callback_info info)279 napi_value PropNExporter::MkdirSync(napi_env env, napi_callback_info info)
280 {
281     NFuncArg funcArg(env, info);
282     if (!funcArg.InitArgs(NARG_CNT::ONE)) {
283         HILOGE("Number of arguments unmatched");
284         NError(EINVAL).ThrowErr(env);
285         return nullptr;
286     }
287 
288     auto [succ, path, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String();
289     if (!succ) {
290         HILOGE("Invalid path from JS first argument");
291         NError(EINVAL).ThrowErr(env);
292         return nullptr;
293     }
294 
295     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> mkdir_req = {
296         new uv_fs_t, CommonFunc::fs_req_cleanup };
297     if (!mkdir_req) {
298         HILOGE("Failed to request heap memory.");
299         NError(ENOMEM).ThrowErr(env);
300         return nullptr;
301     }
302     int ret = uv_fs_mkdir(nullptr, mkdir_req.get(), path.get(), DIR_DEFAULT_PERM, nullptr);
303     if (ret < 0) {
304         HILOGE("Failed to create directory");
305         NError(ret).ThrowErr(env);
306         return nullptr;
307     }
308 
309     return NVal::CreateUndefined(env).val_;
310 }
311 
ReadSync(napi_env env,napi_callback_info info)312 napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info)
313 {
314     NFuncArg funcArg(env, info);
315 
316     if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
317         HILOGE("Number of arguments unmatched");
318         NError(EINVAL).ThrowErr(env);
319         return nullptr;
320     }
321 
322     bool succ = false;
323     int fd = 0;
324     tie(succ, fd) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
325     if (!succ || fd < 0) {
326         HILOGE("Invalid fd from JS first argument");
327         NError(EINVAL).ThrowErr(env);
328         return nullptr;
329     }
330 
331     void *buf = nullptr;
332     size_t len = 0;
333     int64_t offset = -1;
334     tie(succ, buf, len, offset) =
335         CommonFunc::GetReadArg(env, funcArg[NARG_POS::SECOND], funcArg[NARG_POS::THIRD]);
336     if (!succ) {
337         HILOGE("Failed to resolve buf and options");
338         NError(EINVAL).ThrowErr(env);
339         return nullptr;
340     }
341 
342     uv_buf_t buffer = uv_buf_init(static_cast<char *>(buf), static_cast<unsigned int>(len));
343     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> read_req = {
344         new uv_fs_t, CommonFunc::fs_req_cleanup };
345     if (!read_req) {
346         HILOGE("Failed to request heap memory.");
347         NError(ENOMEM).ThrowErr(env);
348         return nullptr;
349     }
350     int ret = uv_fs_read(nullptr, read_req.get(), fd, &buffer, 1, offset, nullptr);
351     if (ret < 0) {
352         HILOGE("Failed to read file for %{public}d", ret);
353         NError(ret).ThrowErr(env);
354         return nullptr;
355     }
356 
357     return NVal::CreateInt64(env, static_cast<int64_t>(ret)).val_;
358 }
359 
ReadExec(shared_ptr<AsyncIOReadArg> arg,char * buf,size_t len,int32_t fd,int64_t offset)360 static NError ReadExec(shared_ptr<AsyncIOReadArg> arg, char *buf, size_t len, int32_t fd, int64_t offset)
361 {
362     uv_buf_t buffer = uv_buf_init(buf, len);
363     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> read_req = {
364         new uv_fs_t, CommonFunc::fs_req_cleanup };
365     if (!read_req) {
366         HILOGE("Failed to request heap memory.");
367         return NError(ENOMEM);
368     }
369     int ret = uv_fs_read(nullptr, read_req.get(), fd, &buffer, 1, offset, nullptr);
370     if (ret < 0) {
371         HILOGE("Failed to read file for %{public}d", ret);
372         return NError(ret);
373     }
374     arg->lenRead = ret;
375     return NError(ERRNO_NOERR);
376 }
377 
Read(napi_env env,napi_callback_info info)378 napi_value PropNExporter::Read(napi_env env, napi_callback_info info)
379 {
380     NFuncArg funcArg(env, info);
381     if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::FOUR)) {
382         HILOGE("Number of arguments unmatched");
383         NError(EINVAL).ThrowErr(env);
384         return nullptr;
385     }
386 
387     bool succ = false;
388     void *buf = nullptr;
389     size_t len = 0;
390     int32_t fd = 0;
391     int64_t offset = -1;
392     tie(succ, fd) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
393     if (!succ || fd < 0) {
394         HILOGE("Invalid fd from JS first argument");
395         NError(EINVAL).ThrowErr(env);
396         return nullptr;
397     }
398 
399     tie(succ, buf, len, offset) =
400         CommonFunc::GetReadArg(env, funcArg[NARG_POS::SECOND], funcArg[NARG_POS::THIRD]);
401     if (!succ) {
402         HILOGE("Failed to resolve buf and options");
403         NError(EINVAL).ThrowErr(env);
404         return nullptr;
405     }
406 
407     auto arg = CreateSharedPtr<AsyncIOReadArg>(NVal(env, funcArg[NARG_POS::SECOND]));
408     if (arg == nullptr) {
409         HILOGE("Failed to request heap memory.");
410         NError(ENOMEM).ThrowErr(env);
411         return nullptr;
412     }
413     auto cbExec = [arg, buf, len, fd, offset]() -> NError {
414         return ReadExec(arg, static_cast<char *>(buf), len, fd, offset);
415     };
416 
417     auto cbCompl = [arg](napi_env env, NError err) -> NVal {
418         if (err) {
419             return { env, err.GetNapiErr(env) };
420         }
421         return { NVal::CreateInt64(env, static_cast<int64_t>(arg->lenRead)) };
422     };
423 
424     NVal thisVar(env, funcArg.GetThisVar());
425     if (funcArg.GetArgc() == NARG_CNT::TWO || (funcArg.GetArgc() == NARG_CNT::THREE &&
426         !NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function))) {
427         return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_READ_NAME, cbExec, cbCompl).val_;
428     } else {
429         int cbIdx = ((funcArg.GetArgc() == NARG_CNT::THREE) ? NARG_POS::THIRD : NARG_POS::FOURTH);
430         NVal cb(env, funcArg[cbIdx]);
431         return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_READ_NAME, cbExec, cbCompl).val_;
432     }
433 }
434 
WriteExec(shared_ptr<AsyncIOWrtieArg> arg,char * buf,size_t len,int32_t fd,int64_t offset)435 static NError WriteExec(shared_ptr<AsyncIOWrtieArg> arg, char *buf, size_t len, int32_t fd, int64_t offset)
436 {
437     uv_buf_t buffer = uv_buf_init(buf, static_cast<unsigned int>(len));
438     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> write_req = {
439         new uv_fs_t, CommonFunc::fs_req_cleanup };
440     if (!write_req) {
441         HILOGE("Failed to request heap memory.");
442         return NError(ENOMEM);
443     }
444     int ret = uv_fs_write(nullptr, write_req.get(), fd, &buffer, 1, offset, nullptr);
445     if (ret < 0) {
446         HILOGE("Failed to write file for %{public}d", ret);
447         return NError(ret);
448     }
449     arg->actLen = ret;
450     return NError(ERRNO_NOERR);
451 }
452 
Write(napi_env env,napi_callback_info info)453 napi_value PropNExporter::Write(napi_env env, napi_callback_info info)
454 {
455     NFuncArg funcArg(env, info);
456     if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::FOUR)) {
457         HILOGE("Number of arguments unmatched");
458         NError(EINVAL).ThrowErr(env);
459         return nullptr;
460     }
461 
462     bool succ = false;
463     int32_t fd = 0;
464     tie(succ, fd) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
465     if (!succ || fd < 0) {
466         HILOGE("Invalid fd from JS first argument");
467         NError(EINVAL).ThrowErr(env);
468         return nullptr;
469     }
470 
471     unique_ptr<char[]> bufGuard = nullptr;
472     void *buf = nullptr;
473     size_t len = 0;
474     int64_t offset = -1;
475     tie(succ, bufGuard, buf, len, offset) =
476         CommonFunc::GetWriteArg(env, funcArg[NARG_POS::SECOND], funcArg[NARG_POS::THIRD]);
477     if (!succ) {
478         HILOGE("Failed to resolve buf and options");
479         NError(EINVAL).ThrowErr(env);
480         return nullptr;
481     }
482 
483     auto arg = CreateSharedPtr<AsyncIOWrtieArg>(move(bufGuard));
484     if (arg == nullptr) {
485         HILOGE("Failed to request heap memory.");
486         NError(ENOMEM).ThrowErr(env);
487         return nullptr;
488     }
489     auto cbExec = [arg, buf, len, fd, offset]() -> NError {
490         return WriteExec(arg, static_cast<char *>(buf), len, fd, offset);
491     };
492 
493     auto cbCompl = [arg](napi_env env, NError err) -> NVal {
494         if (err) {
495             return { env, err.GetNapiErr(env) };
496         } else {
497             return { NVal::CreateInt64(env, static_cast<int64_t>(arg->actLen)) };
498         }
499     };
500 
501     NVal thisVar(env, funcArg.GetThisVar());
502     if (funcArg.GetArgc() == NARG_CNT::TWO || (funcArg.GetArgc() == NARG_CNT::THREE &&
503         !NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function))) {
504         return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_WRITE_NAME, cbExec, cbCompl).val_;
505     } else {
506         int cbIdx = ((funcArg.GetArgc() == NARG_CNT::THREE) ? NARG_POS::THIRD : NARG_POS::FOURTH);
507         NVal cb(env, funcArg[cbIdx]);
508         return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_WRITE_NAME, cbExec, cbCompl).val_;
509     }
510 }
511 
WriteSync(napi_env env,napi_callback_info info)512 napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info)
513 {
514     NFuncArg funcArg(env, info);
515     if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) {
516         HILOGE("Number of arguments unmatched");
517         NError(EINVAL).ThrowErr(env);
518         return nullptr;
519     }
520 
521     bool succ = false;
522     int32_t fd = 0;
523     tie(succ, fd) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32();
524     if (!succ || fd < 0) {
525         HILOGE("Invalid fd from JS first argument");
526         NError(EINVAL).ThrowErr(env);
527         return nullptr;
528     }
529 
530     void *buf = nullptr;
531     size_t len = 0;
532     int64_t offset = -1;
533     unique_ptr<char[]> bufGuard = nullptr;
534     tie(succ, bufGuard, buf, len, offset) =
535         CommonFunc::GetWriteArg(env, funcArg[NARG_POS::SECOND], funcArg[NARG_POS::THIRD]);
536     if (!succ) {
537         HILOGE("Failed to resolve buf and options");
538         return nullptr;
539     }
540 
541     uv_buf_t buffer = uv_buf_init(static_cast<char *>(buf), static_cast<unsigned int>(len));
542     std::unique_ptr<uv_fs_t, decltype(CommonFunc::fs_req_cleanup)*> write_req = {
543         new uv_fs_t, CommonFunc::fs_req_cleanup };
544     if (!write_req) {
545         HILOGE("Failed to request heap memory.");
546         NError(ENOMEM).ThrowErr(env);
547         return nullptr;
548     }
549     int ret = uv_fs_write(nullptr, write_req.get(), fd, &buffer, 1, offset, nullptr);
550     if (ret < 0) {
551         HILOGE("Failed to write file for %{public}d", ret);
552         NError(ret).ThrowErr(env);
553         return nullptr;
554     }
555 
556     return NVal::CreateInt64(env, static_cast<int64_t>(ret)).val_;
557 }
558 
Export()559 bool PropNExporter::Export()
560 {
561     return exports_.AddProp({
562         NVal::DeclareNapiFunction("access", Access),
563         NVal::DeclareNapiFunction("accessSync", AccessSync),
564         NVal::DeclareNapiFunction("close", Close::Async),
565         NVal::DeclareNapiFunction("closeSync", Close::Sync),
566         NVal::DeclareNapiFunction("fdatasync", Fdatasync::Async),
567         NVal::DeclareNapiFunction("fdatasyncSync", Fdatasync::Sync),
568         NVal::DeclareNapiFunction("fsync", Fsync::Async),
569         NVal::DeclareNapiFunction("fsyncSync", Fsync::Sync),
570         NVal::DeclareNapiFunction("lstat", Lstat::Async),
571         NVal::DeclareNapiFunction("lstatSync", Lstat::Sync),
572         NVal::DeclareNapiFunction("mkdir", Mkdir),
573         NVal::DeclareNapiFunction("mkdirSync", MkdirSync),
574         NVal::DeclareNapiFunction("mkdtemp", Mkdtemp::Async),
575         NVal::DeclareNapiFunction("mkdtempSync", Mkdtemp::Sync),
576         NVal::DeclareNapiFunction("open", Open::Async),
577         NVal::DeclareNapiFunction("openSync", Open::Sync),
578         NVal::DeclareNapiFunction("read", Read),
579         NVal::DeclareNapiFunction("readSync", ReadSync),
580         NVal::DeclareNapiFunction("rename", Rename::Async),
581         NVal::DeclareNapiFunction("renameSync", Rename::Sync),
582         NVal::DeclareNapiFunction("rmdir", Rmdirent::Async),
583         NVal::DeclareNapiFunction("rmdirSync", Rmdirent::Sync),
584         NVal::DeclareNapiFunction("stat", Stat::Async),
585         NVal::DeclareNapiFunction("statSync", Stat::Sync),
586         NVal::DeclareNapiFunction("truncate", Truncate::Async),
587         NVal::DeclareNapiFunction("truncateSync", Truncate::Sync),
588         NVal::DeclareNapiFunction("unlink", Unlink),
589         NVal::DeclareNapiFunction("unlinkSync", UnlinkSync),
590         NVal::DeclareNapiFunction("write", Write),
591         NVal::DeclareNapiFunction("writeSync", WriteSync),
592 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM)
593         NVal::DeclareNapiFunction("copyDir", CopyDir::Async),
594         NVal::DeclareNapiFunction("copyDirSync", CopyDir::Sync),
595         NVal::DeclareNapiFunction("copyFile", CopyFile::Async),
596         NVal::DeclareNapiFunction("copyFileSync", CopyFile::Sync),
597         NVal::DeclareNapiFunction("createRandomAccessFile", CreateRandomAccessFile::Async),
598         NVal::DeclareNapiFunction("createRandomAccessFileSync", CreateRandomAccessFile::Sync),
599         NVal::DeclareNapiFunction("createStream", CreateStream::Async),
600         NVal::DeclareNapiFunction("createStreamSync", CreateStream::Sync),
601         NVal::DeclareNapiFunction("dup", Dup::Sync),
602         NVal::DeclareNapiFunction("fdopenStream", FdopenStream::Async),
603         NVal::DeclareNapiFunction("fdopenStreamSync", FdopenStream::Sync),
604         NVal::DeclareNapiFunction("listFile", ListFile::Async),
605         NVal::DeclareNapiFunction("listFileSync", ListFile::Sync),
606         NVal::DeclareNapiFunction("moveDir", MoveDir::Async),
607         NVal::DeclareNapiFunction("moveDirSync", MoveDir::Sync),
608         NVal::DeclareNapiFunction("moveFile", Move::Async),
609         NVal::DeclareNapiFunction("moveFileSync", Move::Sync),
610         NVal::DeclareNapiFunction("readText", ReadText::Async),
611         NVal::DeclareNapiFunction("readTextSync", ReadText::Sync),
612         NVal::DeclareNapiFunction("symlink", Symlink::Async),
613         NVal::DeclareNapiFunction("symlinkSync", Symlink::Sync),
614         NVal::DeclareNapiFunction("createWatcher", Watcher::CreateWatcher),
615 #endif
616     });
617 }
618 
619 #ifdef WIN_PLATFORM
GetNExporterName()620 string PropNExporter::GetNExporterName()
621 #else
622 string PropNExporter::GetClassName()
623 #endif
624 {
625     return PropNExporter::className_;
626 }
627 
PropNExporter(napi_env env,napi_value exports)628 PropNExporter::PropNExporter(napi_env env, napi_value exports) : NExporter(env, exports) {}
629 
~PropNExporter()630 PropNExporter::~PropNExporter() {}
631 } // namespace ModuleFileIO
632 } // namespace FileManagement
633 } // namespace OHOS