1 /*
2 * Copyright (c) 2021-2022 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 "chmod.h"
17
18 #include <cstring>
19 #include <sys/stat.h>
20 #include <tuple>
21 #include <unistd.h>
22
23 #include "../../common/napi/n_async/n_async_work_callback.h"
24 #include "../../common/napi/n_async/n_async_work_promise.h"
25 #include "../../common/napi/n_func_arg.h"
26
27 namespace OHOS {
28 namespace DistributedFS {
29 namespace ModuleFileIO {
30 using namespace std;
31
Sync(napi_env env,napi_callback_info info)32 napi_value Chmod::Sync(napi_env env, napi_callback_info info)
33 {
34 return NVal::CreateUndefined(env).val_;
35 }
36
Async(napi_env env,napi_callback_info info)37 napi_value Chmod::Async(napi_env env, napi_callback_info info)
38 {
39 NFuncArg funcArg(env, info);
40 funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE);
41 auto cbExec = [](napi_env env) -> UniError {
42 return UniError(ERRNO_NOERR);
43 };
44
45 auto cbComplete = [](napi_env env, UniError err) -> NVal {
46 return { NVal::CreateUndefined(env) };
47 };
48
49 NVal thisVar(env, funcArg.GetThisVar());
50 const string procedureName = "FileIOChmod";
51 if (funcArg.GetArgc() == NARG_CNT::TWO) {
52 return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
53 } else {
54 NVal cb(env, funcArg[NARG_POS::THIRD]);
55 return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
56 }
57 }
58 } // namespace ModuleFileIO
59 } // namespace DistributedFS
60 } // namespace OHOS