From: Sangyoon Jang Date: Tue, 12 Sep 2023 07:18:50 +0000 (+0900) Subject: Implement priority list feature in pkg_upgrader X-Git-Tag: accepted/tizen/unified/20231219.160414~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96c90be36e19db6a3230611bb7d2f61dd5ba4020;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Implement priority list feature in pkg_upgrader Change-Id: I4e3e922cf0c8d4a4e7472039976391ddecf99c04 Signed-off-by: Sangyoon Jang --- diff --git a/src/pkg_upgrade/include/pkg_finder.hh b/src/pkg_upgrade/include/pkg_finder.hh index 7da7f15..011b57d 100644 --- a/src/pkg_upgrade/include/pkg_finder.hh +++ b/src/pkg_upgrade/include/pkg_finder.hh @@ -35,14 +35,17 @@ class PkgFinder { virtual int Find(); const std::list& GetOldPkgs() { return old_pkgs_; } const std::list& GetNewPkgs() { return new_pkgs_; } + const std::list& GetPriorityPkgs() { return priority_pkgs_; } void SetManifestDir(std::string dir); void SetPreloadRwListPath(std::string path); + void SetPriorityListPath(std::string path); private: static int PkgidListCb(const pkgmgrinfo_pkginfo_h handle, void* user_data); int FindPreloadPkgidFromDb(bool read_only = true); int FindPreloadPkgidFromXml(const std::string& xml_directory); int FindPreloadPkgidFromFile(); + int FindPriorityPkgs(); std::string GetValidManifest(std::string manifest); std::string FindInfoFromXml(const std::string& manifest, const std::string& find_info); @@ -55,9 +58,11 @@ class PkgFinder { private: std::list old_pkgs_; std::list new_pkgs_; + std::list priority_pkgs_; bool read_only_ = true; std::string manifest_dir_; std::string preload_rw_list_path_; + std::string priority_list_path_; }; } // common_fota diff --git a/src/pkg_upgrade/include/pkg_upgrader_factory.hh b/src/pkg_upgrade/include/pkg_upgrader_factory.hh index 042e995..8cd606a 100644 --- a/src/pkg_upgrade/include/pkg_upgrader_factory.hh +++ b/src/pkg_upgrade/include/pkg_upgrader_factory.hh @@ -30,6 +30,8 @@ namespace common_fota { class PkgUpgraderFactory { public: std::list> MakeList(PkgFinder* finder); + std::list> MakePriorityList(PkgFinder* finder, + std::list>& list); bool IsFailed(); private: diff --git a/src/pkg_upgrade/include/upgrader.hh b/src/pkg_upgrade/include/upgrader.hh index 4d282bd..77479c5 100644 --- a/src/pkg_upgrade/include/upgrader.hh +++ b/src/pkg_upgrade/include/upgrader.hh @@ -48,6 +48,7 @@ class Upgrader { int RemoveBackupFlag(const std::string& path); int IntegrityCheckBackupDbs(); int IntegrityCheck(const std::string& path); + void ProcessList(std::list>& list); private: std::shared_ptr logger_; diff --git a/src/pkg_upgrade/src/pkg_finder.cc b/src/pkg_upgrade/src/pkg_finder.cc index fbf95de..899210b 100644 --- a/src/pkg_upgrade/src/pkg_finder.cc +++ b/src/pkg_upgrade/src/pkg_finder.cc @@ -54,6 +54,7 @@ constexpr char kTokenRemoveStr[] = "removable="; constexpr char kDefaultVersionStr[] = "0.0.1"; constexpr char kDefaultPkgTypeStr[] = "tpk"; constexpr char kRpkTypeStr[] = "rpk"; +constexpr char kPriorityListFile[] = "/etc/package-manager/priority_list"; } // namespace @@ -63,6 +64,7 @@ PkgFinder::PkgFinder() { xmlInitParser(); manifest_dir_ = USR_MANIFEST_DIRECTORY; preload_rw_list_path_ = PRELOAD_RW_LIST_FILE; + priority_list_path_ = kPriorityListFile; if (access(kOptZipFile, F_OK) != 0) { LOG(ERROR) << kOptZipFile << " does not exist"; @@ -108,6 +110,11 @@ int PkgFinder::Find() { return -1; } + if (FindPriorityPkgs() != 0) { + LOG(ERROR) << "FindPriorityPkgs failed"; + return -1; + } + return 0; } @@ -119,6 +126,10 @@ void PkgFinder::SetPreloadRwListPath(std::string path) { preload_rw_list_path_ = std::move(path); } +void PkgFinder::SetPriorityListPath(std::string path) { + priority_list_path_ = std::move(path); +} + int PkgFinder::PkgidListCb(const pkgmgrinfo_pkginfo_h handle, void* user_data) { char* pkgid = nullptr; if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK) @@ -323,6 +334,25 @@ int PkgFinder::FindPreloadPkgidFromFile() { return 0; } +int PkgFinder::FindPriorityPkgs() { + char buf[kBufSize] = {0}; + FILE *fp; + + fp = fopen(priority_list_path_.c_str(), "r"); + if (fp == nullptr) { + LOG(INFO) << "no priority list file"; + return 0; + } + + while (fgets(buf, kBufSize, fp) != NULL) { + StrTrim(buf); + priority_pkgs_.emplace_back(buf); + } + fclose(fp); + + return 0; +} + void PkgFinder::AddRwPkgInfoFromFile(const char* info_str) { if (info_str == nullptr) return; diff --git a/src/pkg_upgrade/src/pkg_upgrader_factory.cc b/src/pkg_upgrade/src/pkg_upgrader_factory.cc index c02c694..4f0ff7f 100644 --- a/src/pkg_upgrade/src/pkg_upgrader_factory.cc +++ b/src/pkg_upgrade/src/pkg_upgrader_factory.cc @@ -16,6 +16,7 @@ #include "pkg_upgrader_factory.hh" +#include #include #include "db_upgrader.hh" @@ -70,6 +71,20 @@ list> PkgUpgraderFactory::MakeList(PkgFinder* finder) { return Merge(finder->GetOldPkgs(), finder->GetNewPkgs()); } +list> PkgUpgraderFactory::MakePriorityList( + PkgFinder* finder, list>& list) { + const auto& pkgs = finder->GetPriorityPkgs(); + auto it = list.begin(); + std::list> priority_list; + while (it != list.end()) { + auto tmp = std::next(it); + if (std::find(pkgs.begin(), pkgs.end(), (*it)->GetId()) != pkgs.end()) + priority_list.splice(priority_list.begin(), list, it); + it = tmp; + } + return priority_list; +} + bool PkgUpgraderFactory::IsFailed() { return failed_; } diff --git a/src/pkg_upgrade/src/upgrader.cc b/src/pkg_upgrade/src/upgrader.cc index b261150..fa4d378 100644 --- a/src/pkg_upgrade/src/upgrader.cc +++ b/src/pkg_upgrade/src/upgrader.cc @@ -136,6 +136,19 @@ bool Upgrader::Process(PkgFinder* finder) { return false; } + auto priority_list = factory.MakePriorityList(finder, list); + + ProcessList(priority_list); + // send signal at this time? + ProcessList(list); + RemoveBackupDbs(); + + logger_->WriteLog(::utils::LogLevel::LOG_INFO, "", "Upgrade Done"); + logger_->WriteLogToFile(); + return true; +} + +void Upgrader::ProcessList(list>& list) { for (auto& pkg : list) { if (pkg->Upgrade()) { LOG(DEBUG) << "upgrade success (" << pkg->GetId() << ")"; @@ -145,12 +158,6 @@ bool Upgrader::Process(PkgFinder* finder) { failure_list_.push_back(move(pkg)); } } - - RemoveBackupDbs(); - - logger_->WriteLog(::utils::LogLevel::LOG_INFO, "", "Upgrade Done"); - logger_->WriteLogToFile(); - return true; } const list>& Upgrader::GetSuccessList() const {