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 class BReportEntity { 40 public: 41 /** 42 * @brief 获取Report信息 43 * 44 * @return std::map<string, ReportFileInfo> 45 */ 46 std::unordered_map<std::string, struct ReportFileInfo> GetReportInfos() const; 47 48 /** 49 * @brief 获取本地Report信息 50 * 51 * @return bool 52 */ 53 bool GetStorageReportInfos(struct ReportFileInfo &fileStat); 54 55 /** 56 * @brief Check if line is encode 57 * 58 */ 59 void CheckAndUpdateIfReportLineEncoded(std::string &path); 60 61 /** 62 * @brief encode report item 63 */ 64 static std::string EncodeReportItem(const std::string &reportItem, bool enableEncode); 65 66 /** 67 * @brief decode report item 68 */ 69 static std::string DecodeReportItem(const std::string &reportItem, bool enableEncode); 70 71 public: 72 /** 73 * @brief 构造方法 74 * 75 * @param fd 76 */ BReportEntity(UniqueFd fd)77 explicit BReportEntity(UniqueFd fd) : srcFile_(std::move(fd)) {} 78 79 BReportEntity() = delete; 80 virtual ~BReportEntity() = default; 81 82 public: 83 unsigned int attrNum = 0; 84 85 protected: 86 UniqueFd srcFile_; 87 }; 88 } // namespace OHOS::FileManagement::Backup 89 90 #endif // OHOS_FILEMGMT_BACKUP_B_REPORT_ENTITY_H