1 /*
2 * Copyright (c) 2020 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 "nativeapi_fs.h"
17 #include <securec.h>
18 #include "ability_env.h"
19 #include "js_async_work.h"
20 #include "nativeapi_common.h"
21 #include "nativeapi_fs_impl.h"
22
23 namespace OHOS {
24 namespace ACELite {
25 namespace {
26 char g_uriFullPath[FILE_NAME_MAX_LEN + 1] = {0};
27 const unsigned int PREFIX_LEN = strlen(FILE_PREFIX);
28
IsValidPath(const char * path)29 bool IsValidPath(const char* path)
30 {
31 if (path == nullptr) {
32 return false;
33 }
34
35 size_t pathLen = strnlen(path, URI_NAME_MAX_LEN + 1);
36 if (pathLen > URI_NAME_MAX_LEN) {
37 return false;
38 }
39 if ((pathLen < PREFIX_LEN) || (strncmp(path, FILE_PREFIX, PREFIX_LEN) != 0)) {
40 return false;
41 }
42 if ((strstr(path, "/./") != nullptr) || (strstr(path, "/../") != nullptr)) {
43 return false;
44 }
45 if (strpbrk(path + PREFIX_LEN, "\"*+,:;<=>\?[]|\x7F")) {
46 return false;
47 }
48 return true;
49 }
50
GetFullPath(const char * uri,char * fullPath,int len)51 int GetFullPath(const char* uri, char* fullPath, int len)
52 {
53 if (!IsValidPath(uri) || (fullPath == nullptr)) {
54 return ERROR_CODE_PARAM;
55 }
56 const char* dataPath = GetDataPath();
57 if (dataPath == nullptr) {
58 return ERROR_CODE_PARAM;
59 }
60 if (memset_s(fullPath, len, 0x0, len) != EOK) {
61 return ERROR_CODE_GENERAL;
62 }
63 if (sprintf_s(fullPath, len, "%s%s", dataPath, uri + PREFIX_LEN) < 0) {
64 return ERROR_CODE_GENERAL;
65 }
66 return NATIVE_SUCCESS;
67 }
68
ExecuteAsyncWork(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum,AsyncWorkHandler ExecuteFunc,bool flag=false)69 JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args,
70 uint8_t argsNum, AsyncWorkHandler ExecuteFunc, bool flag = false)
71 {
72 JSIValue undefValue = JSI::CreateUndefined();
73 if (!NativeapiCommon::IsValidJSIValue(args, argsNum)) {
74 return undefValue;
75 }
76 FuncParams* params = new FuncParams();
77 if (params == nullptr) {
78 return undefValue;
79 }
80 params->thisVal = JSI::AcquireValue(thisVal);
81 params->args = JSI::AcquireValue(args[0]);
82 params->flag = flag;
83 JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast<void *>(params));
84 return undefValue;
85 }
86
ExecuteCopyFile(void * data)87 void ExecuteCopyFile(void* data)
88 {
89 FuncParams* params = reinterpret_cast<FuncParams *>(data);
90 if (params == nullptr) {
91 return;
92 }
93 JSIValue args = params->args;
94 JSIValue thisVal = params->thisVal;
95 char* src = JSI::GetStringProperty(args, FILE_SOURCE_URI);
96 char* dest = JSI::GetStringProperty(args, FILE_DESTINATION_URI);
97 char* destFullPath = nullptr;
98 JSIValue result = JSI::CreateUndefined();
99 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
100 JSI::ReleaseString(src);
101 if (ret != NATIVE_SUCCESS) {
102 NativeapiCommon::FailCallBack(thisVal, args, ret);
103 goto EXIT;
104 }
105 destFullPath = reinterpret_cast<char *>(malloc(FILE_NAME_MAX_LEN + 1));
106 if (destFullPath == nullptr) {
107 NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_GENERAL);
108 goto EXIT;
109 }
110 ret = GetFullPath(dest, destFullPath, FILE_NAME_MAX_LEN + 1);
111 if (ret != NATIVE_SUCCESS) {
112 NativeapiCommon::FailCallBack(thisVal, args, ret);
113 goto EXIT;
114 }
115 ret = CopyFileImpl(g_uriFullPath, destFullPath);
116 if (ret != NATIVE_SUCCESS) {
117 NativeapiCommon::FailCallBack(thisVal, args, ret);
118 goto EXIT;
119 }
120 if (params->flag) {
121 ret = DeleteFileImpl(g_uriFullPath);
122 }
123 if (ret != NATIVE_SUCCESS) {
124 NativeapiCommon::FailCallBack(thisVal, args, ret);
125 goto EXIT;
126 }
127 result = JSI::CreateString(dest);
128 NativeapiCommon::SuccessCallBack(thisVal, args, result);
129 EXIT:
130 JSI::ReleaseString(dest);
131 free(destFullPath);
132 JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
133 delete params;
134 }
135
ExecuteDeleteAccess(void * data)136 void ExecuteDeleteAccess(void* data)
137 {
138 FuncParams* params = reinterpret_cast<FuncParams *>(data);
139 if (params == nullptr) {
140 return;
141 }
142 JSIValue args = params->args;
143 JSIValue thisVal = params->thisVal;
144 char* src = JSI::GetStringProperty(args, FILE_URI);
145 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
146 JSI::ReleaseString(src);
147 if (ret != NATIVE_SUCCESS) {
148 NativeapiCommon::FailCallBack(thisVal, args, ret);
149 goto EXIT;
150 }
151 if (params->flag) {
152 ret = DeleteFileImpl(g_uriFullPath);
153 } else {
154 ret = AccessImpl(g_uriFullPath);
155 }
156 if (ret != NATIVE_SUCCESS) {
157 NativeapiCommon::FailCallBack(thisVal, args, ret);
158 goto EXIT;
159 }
160 NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
161 EXIT:
162 JSI::ReleaseValueList(args, thisVal, ARGS_END);
163 delete params;
164 }
165
GetFileListInner(const char * path,const char * key,JSIValue & result)166 int GetFileListInner(const char* path, const char* key, JSIValue& result)
167 {
168 int fileNum = GetFileNum(g_uriFullPath);
169 if (fileNum <= 0) {
170 return fileNum;
171 }
172 FileMetaInfo* fileList = reinterpret_cast<FileMetaInfo *>(malloc(fileNum * sizeof(FileMetaInfo)));
173 if (fileList == nullptr) {
174 return ERROR_CODE_GENERAL;
175 }
176 if (memset_s(fileList, fileNum * sizeof(FileMetaInfo), 0x0, fileNum * sizeof(FileMetaInfo)) != EOK) {
177 free(fileList);
178 return ERROR_CODE_GENERAL;
179 }
180 int ret = GetFileListImpl(g_uriFullPath, fileList, fileNum);
181 if (ret != NATIVE_SUCCESS) {
182 free(fileList);
183 return ret;
184 }
185 JSIValue arrayValue = JSI::CreateArray(fileNum);
186 for (int i = 0; i < fileNum; i++) {
187 JSIValue tmp = JSI::CreateObject();
188 JSI::SetStringProperty(tmp, FILE_URI, fileList[i].fileName);
189 JSI::SetNumberProperty(tmp, FILE_LENGTH, fileList[i].fileSize);
190 JSI::SetNumberProperty(tmp, FILE_LAST_MODIFIED_TIME, fileList[i].fileMtime);
191 JSI::SetStringProperty(tmp, FILE_TYPE, TYPE_FILE);
192 if (S_ISDIR(fileList[i].fileMode)) {
193 JSI::SetStringProperty(tmp, FILE_TYPE, TYPE_DIR);
194 }
195 JSI::SetPropertyByIndex(arrayValue, i, tmp);
196 JSI::ReleaseValue(tmp);
197 }
198 free(fileList);
199 JSI::SetNamedProperty(result, key, arrayValue);
200 JSI::ReleaseValue(arrayValue);
201 return NATIVE_SUCCESS;
202 }
203
ExecuteGetFileList(void * data)204 void ExecuteGetFileList(void* data)
205 {
206 FuncParams* params = reinterpret_cast<FuncParams *>(data);
207 if (params == nullptr) {
208 return;
209 }
210 JSIValue args = params->args;
211 JSIValue thisVal = params->thisVal;
212 char* uri = JSI::GetStringProperty(args, FILE_URI);
213 JSIValue result = JSI::CreateObject();
214 int ret = GetFullPath(uri, g_uriFullPath, sizeof(g_uriFullPath));
215 JSI::ReleaseString(uri);
216 if (ret != NATIVE_SUCCESS) {
217 NativeapiCommon::FailCallBack(thisVal, args, ret);
218 goto EXIT;
219 }
220 if (params->flag) {
221 ret = GetFileListInner(g_uriFullPath, FILE_LIST, result);
222 } else {
223 ret = GetFileListInner(g_uriFullPath, SUB_FILES, result);
224 }
225 if (ret != NATIVE_SUCCESS) {
226 NativeapiCommon::FailCallBack(thisVal, args, ret);
227 goto EXIT;
228 }
229 NativeapiCommon::SuccessCallBack(thisVal, args, result);
230 EXIT:
231 JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
232 delete params;
233 }
234
ExecuteGetFileInfo(void * data)235 void ExecuteGetFileInfo(void* data)
236 {
237 FuncParams* params = reinterpret_cast<FuncParams *>(data);
238 if (params == nullptr) {
239 return;
240 }
241 JSIValue args = params->args;
242 JSIValue thisVal = params->thisVal;
243 char* src = JSI::GetStringProperty(args, FILE_URI);
244 bool recursive = JSI::GetBooleanProperty(args, RECURSIVE);
245 struct stat info = {0};
246 JSIValue result = JSI::CreateObject();
247 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
248 if (ret != NATIVE_SUCCESS) {
249 NativeapiCommon::FailCallBack(thisVal, args, ret);
250 goto EXIT;
251 }
252 ret = StatImpl(g_uriFullPath, &info);
253 if (ret != NATIVE_SUCCESS) {
254 NativeapiCommon::FailCallBack(thisVal, args, ret);
255 goto EXIT;
256 }
257 if (recursive && (S_ISDIR(info.st_mode))) {
258 JSI::ReleaseString(src);
259 ExecuteGetFileList(data);
260 return;
261 }
262 JSI::SetStringProperty(result, FILE_URI, src);
263 JSI::SetNumberProperty(result, FILE_LENGTH, info.st_size);
264 JSI::SetNumberProperty(result, FILE_LAST_MODIFIED_TIME, info.st_mtime);
265 JSI::SetStringProperty(result, FILE_TYPE, TYPE_FILE);
266 if (S_ISDIR(info.st_mode)) {
267 JSI::SetStringProperty(result, FILE_TYPE, TYPE_DIR);
268 }
269 NativeapiCommon::SuccessCallBack(thisVal, args, result);
270 EXIT:
271 JSI::ReleaseString(src);
272 JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
273 delete params;
274 }
275
ExecuteWriteTextFile(void * data)276 void ExecuteWriteTextFile(void* data)
277 {
278 FuncParams* params = reinterpret_cast<FuncParams *>(data);
279 if (params == nullptr) {
280 return;
281 }
282 JSIValue args = params->args;
283 JSIValue thisVal = params->thisVal;
284 char* src = JSI::GetStringProperty(args, FILE_URI);
285 char* text = JSI::GetStringProperty(args, TEXT);
286 bool append = JSI::GetBooleanProperty(args, FILE_APPEND);
287 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
288 JSI::ReleaseString(src);
289 if ((text == nullptr) || (ret != NATIVE_SUCCESS)) {
290 NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_PARAM);
291 goto EXIT;
292 }
293 ret = WriteTextFile(g_uriFullPath, text, strlen(text), append);
294 if (ret != NATIVE_SUCCESS) {
295 NativeapiCommon::FailCallBack(thisVal, args, ret);
296 goto EXIT;
297 }
298 NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
299 EXIT:
300 JSI::ReleaseString(text);
301 JSI::ReleaseValueList(args, thisVal, ARGS_END);
302 delete params;
303 }
304
ReadTextInner(const char * src,int position,int length,JSIValue & result)305 int ReadTextInner(const char* src, int position, int length, JSIValue& result)
306 {
307 if ((position < 0) || (length < 0)) {
308 return ERROR_CODE_PARAM;
309 }
310 if (length == 0) {
311 length = TEXT_MAX_READ_LEN;
312 }
313 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
314 if (ret != NATIVE_SUCCESS) {
315 return ret;
316 }
317 struct stat info = {0};
318 ret = StatImpl(g_uriFullPath, &info);
319 if (ret != NATIVE_SUCCESS) {
320 return ret;
321 }
322 size_t readLen = (info.st_size > length) ? length : info.st_size;
323 if (readLen > TEXT_MAX_READ_LEN) {
324 return ERROR_CODE_READ_TOO_LONG;
325 }
326 char* text = reinterpret_cast<char *>(malloc(readLen + 1));
327 if (text == nullptr) {
328 return ERROR_CODE_GENERAL;
329 }
330 size_t actualLen = 0;
331 ret = ReadFileImpl(g_uriFullPath, text, readLen, position, &actualLen);
332 if (ret != NATIVE_SUCCESS) {
333 free(text);
334 return ret;
335 }
336 text[actualLen] = '\0';
337 JSI::SetStringProperty(result, TEXT, text);
338 free(text);
339 return NATIVE_SUCCESS;
340 }
341
ExecuteReadTextFile(void * data)342 void ExecuteReadTextFile(void* data)
343 {
344 FuncParams* params = reinterpret_cast<FuncParams *>(data);
345 if (params == nullptr) {
346 return;
347 }
348 JSIValue args = params->args;
349 JSIValue thisVal = params->thisVal;
350 char* src = JSI::GetStringProperty(args, FILE_URI);
351 double position = JSI::GetNumberProperty(args, FILE_POSITION);
352 double length = JSI::GetNumberProperty(args, FILE_LENGTH);
353 JSIValue result = JSI::CreateObject();
354 int ret = ReadTextInner(src, position, length, result);
355 JSI::ReleaseString(src);
356 if (ret == NATIVE_SUCCESS) {
357 NativeapiCommon::SuccessCallBack(thisVal, args, result);
358 } else {
359 NativeapiCommon::FailCallBack(thisVal, args, ret);
360 }
361 JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
362 delete params;
363 }
364
ExecuteDirFunc(void * data)365 void ExecuteDirFunc(void* data)
366 {
367 FuncParams* params = reinterpret_cast<FuncParams *>(data);
368 if (params == nullptr) {
369 return;
370 }
371 JSIValue args = params->args;
372 JSIValue thisVal = params->thisVal;
373 char* src = JSI::GetStringProperty(args, FILE_URI);
374 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
375 JSI::ReleaseString(src);
376 bool recursive = JSI::GetBooleanProperty(args, RECURSIVE);
377 if (ret != NATIVE_SUCCESS) {
378 NativeapiCommon::FailCallBack(thisVal, args, ret);
379 goto EXIT;
380 }
381 if (params->flag) {
382 ret = CreateDirImpl(g_uriFullPath, recursive);
383 } else {
384 ret = RemoveDirImpl(g_uriFullPath, recursive);
385 }
386 if (ret != NATIVE_SUCCESS) {
387 NativeapiCommon::FailCallBack(thisVal, args, ret);
388 goto EXIT;
389 }
390 NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
391 EXIT:
392 JSI::ReleaseValueList(args, thisVal, ARGS_END);
393 delete params;
394 }
395 #if (JS_FWK_TYPEDARRAY == NATIVE_FEATURE_ON)
ReadArrayFileInner(const char * path,size_t len,unsigned int position,JSIValue & result)396 int ReadArrayFileInner(const char* path, size_t len, unsigned int position, JSIValue& result)
397 {
398 struct stat info = {0};
399 int ret = StatImpl(path, &info);
400 if (ret != NATIVE_SUCCESS) {
401 return ret;
402 }
403 void* text = malloc(info.st_size + 1);
404 if (text == nullptr) {
405 return ERROR_CODE_GENERAL;
406 }
407 size_t actualLen = 0;
408 ret = ReadFileImpl(path, text, len, static_cast<int>(position), &actualLen);
409 if (ret != NATIVE_SUCCESS) {
410 free(text);
411 return ret;
412 }
413 uint8_t* ptr = nullptr;
414 JSIValue arrayBuffer = JSI::CreateArrayBuffer(actualLen, ptr);
415 if (ptr == nullptr) {
416 free(text);
417 JSI::ReleaseValue(arrayBuffer);
418 return ERROR_CODE_GENERAL;
419 }
420 ret = memcpy_s(ptr, actualLen, text, actualLen);
421 free(text);
422 if (ret != EOK) {
423 JSI::ReleaseValue(arrayBuffer);
424 return ERROR_CODE_GENERAL;
425 }
426 JSIValue typedArray = JSI::CreateTypedArray(TypedArrayType::JSI_UINT8_ARRAY, actualLen, arrayBuffer, 0);
427 JSI::SetNamedProperty(result, FILE_BUFFER, typedArray);
428 JSI::ReleaseValueList(typedArray, arrayBuffer, ARGS_END);
429 return NATIVE_SUCCESS;
430 }
431
ExecuteReadArrayFile(void * data)432 void ExecuteReadArrayFile(void* data)
433 {
434 FuncParams* params = reinterpret_cast<FuncParams *>(data);
435 if (params == nullptr) {
436 return;
437 }
438 JSIValue args = params->args;
439 JSIValue thisVal = params->thisVal;
440 char* src = JSI::GetStringProperty(args, FILE_URI);
441 double position = JSI::GetNumberProperty(args, FILE_POSITION);
442 double length = JSI::GetNumberProperty(args, FILE_LENGTH);
443 JSIValue result = JSI::CreateObject();
444 int ret = ERROR_CODE_PARAM;
445 if ((position < 0) || (length < 0)) {
446 JSI::ReleaseString(src);
447 NativeapiCommon::FailCallBack(thisVal, args, ret);
448 goto EXIT;
449 }
450 ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
451 JSI::ReleaseString(src);
452 if (ret != NATIVE_SUCCESS) {
453 NativeapiCommon::FailCallBack(thisVal, args, ret);
454 goto EXIT;
455 }
456 ret = ReadArrayFileInner(g_uriFullPath, static_cast<int>(length), static_cast<int>(position), result);
457 if (ret != NATIVE_SUCCESS) {
458 NativeapiCommon::FailCallBack(thisVal, args, ret);
459 goto EXIT;
460 }
461 NativeapiCommon::SuccessCallBack(thisVal, args, result);
462 EXIT:
463 JSI::ReleaseValueList(args, thisVal, result, ARGS_END);
464 delete params;
465 }
466
ExecuteWriteArrayFile(void * data)467 void ExecuteWriteArrayFile(void* data)
468 {
469 FuncParams* params = reinterpret_cast<FuncParams *>(data);
470 if (params == nullptr) {
471 return;
472 }
473 JSIValue args = params->args;
474 JSIValue thisVal = params->thisVal;
475 char* src = JSI::GetStringProperty(args, FILE_URI);
476 int ret = GetFullPath(src, g_uriFullPath, sizeof(g_uriFullPath));
477 JSI::ReleaseString(src);
478 if (ret != NATIVE_SUCCESS) {
479 NativeapiCommon::FailCallBack(thisVal, args, ret);
480 JSI::ReleaseValueList(args, thisVal, ARGS_END);
481 delete params;
482 return;
483 }
484 JSIValue buffer = JSI::GetNamedProperty(args, FILE_BUFFER);
485 double position = JSI::GetNumberProperty(args, FILE_POSITION);
486 bool append = JSI::GetBooleanProperty(args, FILE_APPEND);
487 TypedArrayType type = TypedArrayType::JSI_INVALID_ARRAY;
488 size_t length = 0;
489 JSIValue arrayBuffer = JSI::CreateUndefined();
490 size_t byteOffset = 0;
491 uint8_t* arrayPtr = JSI::GetTypedArrayInfo(buffer, type, length, arrayBuffer, byteOffset);
492 ret = ERROR_CODE_PARAM;
493 if ((position < 0) || (arrayPtr == nullptr) || (type != TypedArrayType::JSI_UINT8_ARRAY)) {
494 JSI::ReleaseValueList(buffer, arrayBuffer, ARGS_END);
495 NativeapiCommon::FailCallBack(thisVal, args, ERROR_CODE_PARAM);
496 goto EXIT;
497 }
498 ret = WriteArrayFile(g_uriFullPath, arrayPtr, length, static_cast<int>(position), append);
499 JSI::ReleaseValueList(buffer, arrayBuffer, ARGS_END);
500 if (ret != NATIVE_SUCCESS) {
501 NativeapiCommon::FailCallBack(thisVal, args, ret);
502 goto EXIT;
503 }
504 NativeapiCommon::SuccessCallBack(thisVal, args, JSI::CreateUndefined());
505 EXIT:
506 JSI::ReleaseValueList(args, thisVal, ARGS_END);
507 delete params;
508 }
509 #endif
510 }
511
InitNativeApiFs(JSIValue exports)512 void InitNativeApiFs(JSIValue exports)
513 {
514 JSI::SetModuleAPI(exports, "move", NativeapiFs::MoveFile);
515 JSI::SetModuleAPI(exports, "copy", NativeapiFs::CopyFile);
516 JSI::SetModuleAPI(exports, "delete", NativeapiFs::DeleteFile);
517 JSI::SetModuleAPI(exports, "list", NativeapiFs::GetFileList);
518 JSI::SetModuleAPI(exports, "get", NativeapiFs::GetFileInfo);
519 JSI::SetModuleAPI(exports, "readText", NativeapiFs::ReadTextFile);
520 JSI::SetModuleAPI(exports, "writeText", NativeapiFs::WriteTextFile);
521 JSI::SetModuleAPI(exports, "access", NativeapiFs::Access);
522 JSI::SetModuleAPI(exports, "mkdir", NativeapiFs::CreateDir);
523 JSI::SetModuleAPI(exports, "rmdir", NativeapiFs::RemoveDir);
524
525 #if (JS_FWK_TYPEDARRAY == NATIVE_FEATURE_ON)
526 JSI::SetModuleAPI(exports, "readArrayBuffer", NativeapiFs::ReadArrayFile);
527 JSI::SetModuleAPI(exports, "writeArrayBuffer", NativeapiFs::WriteArrayFile);
528 #endif
529 }
530
MoveFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)531 JSIValue NativeapiFs::MoveFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
532 {
533 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteCopyFile, true);
534 }
535
CopyFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)536 JSIValue NativeapiFs::CopyFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
537 {
538 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteCopyFile);
539 }
540
DeleteFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)541 JSIValue NativeapiFs::DeleteFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
542 {
543 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDeleteAccess, true);
544 }
545
GetFileList(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)546 JSIValue NativeapiFs::GetFileList(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
547 {
548 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetFileList, true);
549 }
550
GetFileInfo(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)551 JSIValue NativeapiFs::GetFileInfo(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
552 {
553 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetFileInfo);
554 }
555
WriteTextFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)556 JSIValue NativeapiFs::WriteTextFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
557 {
558 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteWriteTextFile);
559 }
560
ReadTextFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)561 JSIValue NativeapiFs::ReadTextFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
562 {
563 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteReadTextFile);
564 }
565
Access(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)566 JSIValue NativeapiFs::Access(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
567 {
568 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDeleteAccess);
569 }
570
CreateDir(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)571 JSIValue NativeapiFs::CreateDir(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
572 {
573 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDirFunc, true);
574 }
575
RemoveDir(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)576 JSIValue NativeapiFs::RemoveDir(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
577 {
578 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteDirFunc);
579 }
580
581 #if (JS_FWK_TYPEDARRAY == NATIVE_FEATURE_ON)
ReadArrayFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)582 JSIValue NativeapiFs::ReadArrayFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
583 {
584 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteReadArrayFile);
585 }
586
WriteArrayFile(const JSIValue thisVal,const JSIValue * args,uint8_t argsNum)587 JSIValue NativeapiFs::WriteArrayFile(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum)
588 {
589 return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteWriteArrayFile);
590 }
591 #endif
592 } // ACELite
593 } // OHOS
594