virtual int Find();
const std::list<PkgContext>& GetOldPkgs() { return old_pkgs_; }
const std::list<PkgContext>& GetNewPkgs() { return new_pkgs_; }
+ const std::list<std::string>& 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);
private:
std::list<PkgContext> old_pkgs_;
std::list<PkgContext> new_pkgs_;
+ std::list<std::string> priority_pkgs_;
bool read_only_ = true;
std::string manifest_dir_;
std::string preload_rw_list_path_;
+ std::string priority_list_path_;
};
} // common_fota
class PkgUpgraderFactory {
public:
std::list<std::unique_ptr<PkgUpgrader>> MakeList(PkgFinder* finder);
+ std::list<std::unique_ptr<PkgUpgrader>> MakePriorityList(PkgFinder* finder,
+ std::list<std::unique_ptr<PkgUpgrader>>& list);
bool IsFailed();
private:
int RemoveBackupFlag(const std::string& path);
int IntegrityCheckBackupDbs();
int IntegrityCheck(const std::string& path);
+ void ProcessList(std::list<std::unique_ptr<PkgUpgrader>>& list);
private:
std::shared_ptr<utils::FileLogBackend> logger_;
constexpr char kDefaultVersionStr[] = "0.0.1";
constexpr char kDefaultPkgTypeStr[] = "tpk";
constexpr char kRpkTypeStr[] = "rpk";
+constexpr char kPriorityListFile[] = "/etc/package-manager/priority_list";
} // namespace
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";
return -1;
}
+ if (FindPriorityPkgs() != 0) {
+ LOG(ERROR) << "FindPriorityPkgs failed";
+ return -1;
+ }
+
return 0;
}
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)
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;
#include "pkg_upgrader_factory.hh"
+#include <algorithm>
#include <memory>
#include "db_upgrader.hh"
return Merge(finder->GetOldPkgs(), finder->GetNewPkgs());
}
+list<unique_ptr<PkgUpgrader>> PkgUpgraderFactory::MakePriorityList(
+ PkgFinder* finder, list<unique_ptr<PkgUpgrader>>& list) {
+ const auto& pkgs = finder->GetPriorityPkgs();
+ auto it = list.begin();
+ std::list<std::unique_ptr<PkgUpgrader>> 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_;
}
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<unique_ptr<PkgUpgrader>>& list) {
for (auto& pkg : list) {
if (pkg->Upgrade()) {
LOG(DEBUG) << "upgrade success (" << pkg->GetId() << ")";
failure_list_.push_back(move(pkg));
}
}
-
- RemoveBackupDbs();
-
- logger_->WriteLog(::utils::LogLevel::LOG_INFO, "", "Upgrade Done");
- logger_->WriteLogToFile();
- return true;
}
const list<unique_ptr<PkgUpgrader>>& Upgrader::GetSuccessList() const {