• 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 #ifndef DISTRIBUTED_FILE_SIZE_UTILS_H
17 #define DISTRIBUTED_FILE_SIZE_UTILS_H
18 
19 #include <dirent.h>
20 #include <memory>
21 #include <string>
22 
23 
24 namespace OHOS {
25 namespace Storage {
26 namespace DistributedFile {
27 
28 struct NameList {
29     struct dirent **namelist = { nullptr };
30     int direntNum = 0;
31 };
32 
33 class FileSizeUtils {
34 public:
35     static int32_t GetSize(const std::string &uri, bool isSrcUri, uint64_t &size);
36     static int32_t IsDirectory(const std::string &uri, bool isSrcUri, bool &isDirectory);
37 
38     static std::string GetPathFromUri(const std::string &uri, bool isSrcUri);
39     static int32_t GetFileSize(const std::string &path, uint64_t &size);
40     static int32_t GetDirSize(const std::string &path, uint64_t &size);
41     static void Deleter(struct NameList *arg);
42     static std::unique_ptr<struct NameList, decltype(FileSizeUtils::Deleter) *> GetDirNameList(const std::string &path);
43     static std::string GetRealUri(const std::string &uri);
44     static bool IsFilePathValid(const std::string &filePath);
45     static int32_t IsFile(const std::string &path, bool &result);
46     static int32_t IsDirectory(const std::string &path, bool &result);
47 
48 private:
49     static int FilterFunc(const struct dirent *filename);
50     static std::string GetRealPath(const std::string &path);
51 };
52 } // namespace DistributedFile
53 } // namespace Storage
54 } // namespace OHOS
55 #endif // DISTRIBUTED_FILE_SIZE_UTILS_H
56