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