• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "lstat_ani.h"
17 
18 #include <iostream>
19 #include <string>
20 
21 #include "error_handler.h"
22 #include "filemgmt_libhilog.h"
23 #include "lstat_core.h"
24 #include "stat_wrapper.h"
25 #include "type_converter.h"
26 
27 namespace OHOS {
28 namespace FileManagement {
29 namespace ModuleFileIO {
30 namespace ANI {
31 using namespace std;
32 using namespace OHOS::FileManagement::ModuleFileIO;
33 
LstatSync(ani_env * env,ani_class clazz,ani_string path)34 ani_object LstatAni::LstatSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path)
35 {
36     auto [succPath, filePath] = TypeConverter::ToUTF8String(env, path);
37     if (!succPath) {
38         HILOGE("The first argument requires filepath");
39         ErrorHandler::Throw(env, EINVAL);
40         return {};
41     }
42 
43     auto ret = LstatCore::DoLstat(filePath);
44     if (!ret.IsSuccess()) {
45         HILOGE("DoStat failed!");
46         const FsError &err = ret.GetError();
47         ErrorHandler::Throw(env, err);
48         return {};
49     }
50 
51     auto fsStat = ret.GetData().value();
52     auto statObject = StatWrapper::Wrap(env, fsStat);
53     if (statObject == nullptr) {
54         delete fsStat;
55         fsStat = nullptr;
56         HILOGE("Wrap stat object failed!");
57         ErrorHandler::Throw(env, UNKNOWN_ERR);
58         return {};
59     }
60 
61     return statObject;
62 }
63 } // namespace ANI
64 } // namespace ModuleFileIO
65 } // namespace FileManagement
66 } // namespace OHOS