1 /* 2 * Copyright (c) 2023 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 SYS_INSTALLER_MODULE_FILE_REPOSITORY_H 17 #define SYS_INSTALLER_MODULE_FILE_REPOSITORY_H 18 19 #include <memory> 20 #include <unordered_map> 21 #include <unordered_set> 22 23 #include "module_file.h" 24 #include "module_utils.h" 25 #include "singleton.h" 26 27 namespace OHOS { 28 namespace SysInstaller { 29 class ModuleFileRepository final { 30 public: 31 DISALLOW_COPY_AND_MOVE(ModuleFileRepository); 32 ModuleFileRepository() = default; 33 ~ModuleFileRepository(); 34 void InitRepository(const std::string &hmpName, const Timer &timer); 35 std::unique_ptr<ModuleFile> GetModuleFile(const std::string &pathPrefix, const std::string &hmpName) const; 36 bool IsPreInstalledModule(const ModuleFile &moduleFile) const; 37 void Clear(); 38 void SaveInstallerResult(const std::string &path, const std::string &hmpName, 39 int result, const std::string &resultInfo, const Timer &timer) const; 40 private: 41 void ProcessFile(const std::string &hmpName, const std::string &path, const std::string &file, 42 std::unordered_map<std::string, ModuleFile> &fileMap, const Timer &timer) const; 43 bool CheckFilePath(const ModuleFile &moduleFile, const std::string &prefix) const; 44 45 std::unordered_map<std::string, std::unordered_map<std::string, ModuleFile>> moduleFileMap_; 46 }; 47 } // SysInstaller 48 } // namespace OHOS 49 #endif // SYS_INSTALLER_MODULE_FILE_REPOSITORY_H