#include <regex>
#include <string>
#include <iostream>
+#include <utility>
+#include <vector>
namespace bf = boost::filesystem;
namespace bs = boost::system;
namespace {
+typedef std::pair<std::string, std::string> RecoverEntry;
+
const char kRecoveryFilePattern[] = "^(.*)-recovery-(.*)";
const char kRecoveryMethodName[] = "RecoverPkg";
const char kDBusServiceName[] = "org.tizen.pkg_recovery";
return result;
}
-bool DoRecoveryProcess(uid_t uid) {
- bf::path recovery_dir = ci::GetRootAppPath(false, uid);
+std::vector<RecoverEntry> SearchRecoveryFiles(uid_t uid) {
+ std::vector<RecoverEntry> list;
+ const bf::path recovery_dir = ci::GetRootAppPath(false, uid);
for (bf::directory_iterator iter(recovery_dir);
iter != bf::directory_iterator();
++iter) {
if (std::regex_search(file, match, recovery_regex)) {
LOG(INFO) << "Found recovery file: " << file;
std::string type(match[1]);
- if (!RequestRecoveryService(uid, type.c_str(), iter->path().c_str()))
- LOG(ERROR) << "Failed to recover installation: " << file;
+ list.emplace_back(type, iter->path().string());
}
}
- return true;
+ return list;
}
} // namespace
int main() {
uid_t uid = getuid();
+ std::vector<std::pair<std::string, std::string>> list;
try {
- DoRecoveryProcess(uid);
- if (ci::IsAdminUser(uid))
- DoRecoveryProcess(kGlobalUserUid);
+ list = SearchRecoveryFiles(uid);
+ for (auto entry : list) {
+ if (!RequestRecoveryService(uid, entry.first.c_str(),
+ entry.second.c_str()))
+ LOG(ERROR) << "Failed to recover installation: " << entry.second;
+ }
+
+ if (ci::IsAdminUser(uid)) {
+ list = SearchRecoveryFiles(kGlobalUserUid);
+ for (auto entry : list) {
+ if (!RequestRecoveryService(uid, entry.first.c_str(),
+ entry.second.c_str()))
+ LOG(ERROR) << "Failed to recover installation: " << entry.second;
+ }
+ }
} catch (const bf::filesystem_error& e) {
LOG(ERROR) << "Exception occurred: " << e.what();
return -1;