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