ASSERT_EQ(i , 1);
}
+BackendInterface::CommandResult BackendInterface::RunInstallersWithPkgmgr(
+ ci::PkgMgrPtr pkgmgr) const {
+ std::list<AppInstallerPtr> installers;
+ for (int i = 0; i < pkgmgr->GetRequestInfoCount(); i++) {
+ AppInstallerPtr installer;
+ if (mode_ == RequestResult::FAIL && i == pkgmgr->GetRequestInfoCount() - 1)
+ installer = factory_->CreateFailExpectedInstaller(i, pkgmgr);
+ else
+ installer = factory_->CreateInstaller(i, pkgmgr);
+ if (!installer)
+ LOG(ERROR) << "Failed to create installer";
+ else
+ installers.emplace_back(std::move(installer));
+ }
+
+ // FIXME: I think we should not implement this logic here...
+ CommandResult result = CommandResult::OK;
+ std::list<AppInstallerPtr>::iterator it(installers.begin());
+ for (; it != installers.end(); ++it) {
+ result = (*it)->Process();
+ if (result != CommandResult::OK)
+ break;
+ }
+ if (it != installers.end() && result == CommandResult::ERROR) {
+ do {
+ CommandResult ret = (*it)->Undo();
+ if (ret != CommandResult::OK && ret != CommandResult::ERROR)
+ result = CommandResult::UNDO_ERROR;
+ } while (it-- != installers.begin());
+ } else {
+ --it;
+ do {
+ if ((*it)->Clean() != CommandResult::OK)
+ result = CommandResult::CLEANUP_ERROR;
+ } while (it-- != installers.begin());
+ }
+ return result;
+}
+
+BackendInterface::CommandResult BackendInterface::CallBackendWithRunner(
+ int argc, const char* argv[]) const {
+ TestPkgmgrInstaller pkgmgr_installer;
+ auto pkgmgr = ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
+ &pkgmgr_installer);
+ if (!pkgmgr) {
+ LOG(ERROR) << "Failed to initialize pkgmgr interface";
+ return BackendInterface::CommandResult::UNKNOWN;
+ }
+ return RunInstallersWithPkgmgr(pkgmgr);
+}
+
+BackendInterface::CommandResult BackendInterface::Install(
+ const std::vector<bf::path>& paths) const {
+ std::vector<const char*> argv;
+ argv.emplace_back("");
+ argv.emplace_back("-i");
+ for (const auto& p : paths)
+ argv.emplace_back(p.string().c_str());
+ return CallBackendWithRunner(argv.size(), argv.data());
+}
+
+BackendInterface::CommandResult BackendInterface::InstallSuccess(
+ const std::vector<bf::path>& paths) const {
+ RequestResult tmp_mode = mode_;
+ RequestResult &original_mode = const_cast<RequestResult&>(mode_);
+ original_mode = RequestResult::NORMAL;
+ if (Install(paths) != BackendInterface::CommandResult::OK) {
+ LOG(ERROR) << "Failed to install application. Cannot update";
+ return BackendInterface::CommandResult::UNKNOWN;
+ }
+ original_mode = tmp_mode;
+ return BackendInterface::CommandResult::OK;
+}
+
BackendInterface::CommandResult BackendInterface::RunInstallerWithPkgrmgr(
ci::PkgMgrPtr pkgmgr) const {
std::unique_ptr<ci::AppInstaller> installer;