• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_FILEMGMT_BACKUP_B_REPORT_ENTITY_H
17 #define OHOS_FILEMGMT_BACKUP_B_REPORT_ENTITY_H
18 #define FILE_DEFAULT_MODE "0660"
19 
20 #include <fcntl.h>
21 #include <map>
22 #include <string>
23 
24 #include "unique_fd.h"
25 
26 namespace OHOS::FileManagement::Backup {
27 struct ReportFileInfo {
28     std::string filePath;
29     std::string mode {FILE_DEFAULT_MODE};
30     bool isDir {false};
31     off_t size {0};
32     off_t mtime {0};
33     std::string hash;
34     bool isIncremental {false};
35     off_t userTar {0};
36     bool encodeFlag {false};
37 };
38 
39 enum class KeyType {
40     PATH,
41     MODE,
42     DIR,
43     SIZE,
44     MTIME,
45     HASH,
46     IS_INCREMENTAL,
47     ENCODE_FLAG
48 };
49 
50 class BReportEntity {
51 public:
52     /**
53      * @brief 获取Report信息
54      */
55     void GetReportInfos(std::unordered_map<std::string, struct ReportFileInfo> &infos) const;
56 
57     /**
58      * @brief 获取本地Report信息
59      *
60      * @return bool
61      */
62     bool GetStorageReportInfos(std::unordered_map<std::string, struct ReportFileInfo> &infos);
63 
64     /**
65      * @brief Check if line is encode
66      *
67      */
68     void CheckAndUpdateIfReportLineEncoded(std::string &path);
69 
70     /**
71      * @brief encode report item
72      */
73     static std::string EncodeReportItem(const std::string &reportItem, bool enableEncode);
74 
75     /**
76      * @brief decode report item
77      */
78     static std::string DecodeReportItem(const std::string &reportItem, bool enableEncode);
79 
80 public:
81     /**
82      * @brief 构造方法
83      *
84      * @param fd
85      */
BReportEntity(UniqueFd fd)86     explicit BReportEntity(UniqueFd fd) : srcFile_(std::move(fd)) {}
87 
88     BReportEntity() = delete;
89     virtual ~BReportEntity() = default;
90 
91 public:
92     unsigned int attrNum = 0;
93 
94 protected:
95     UniqueFd srcFile_;
96 private:
97     std::string currLineInfo_;
98     int currLineNum_ = 0;
99     std::vector<std::string> keys_;
100 };
101 } // namespace OHOS::FileManagement::Backup
102 
103 #endif // OHOS_FILEMGMT_BACKUP_B_REPORT_ENTITY_H