PKG_CHECK_MODULES(RPK_INSTALLER_DEPS REQUIRED rpk-installer)
PKG_CHECK_MODULES(LIBXML_DEPS REQUIRED libxml-2.0)
-FIND_PACKAGE(Boost REQUIRED COMPONENTS system filesystem regex program_options)
-
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
Source1002: unified-installer-tests.manifest
BuildRequires: app-installers-tests
-BuildRequires: boost-devel
BuildRequires: cmake
BuildRequires: tpk-installer-tests
BuildRequires: wgt-installer-tests
#include <common/installer/app_installer.h>
#include <common/installer_factory.h>
#include <common/installer_runner.h>
+#include <manifest_parser/utils/logging.h>
#include "unified/unified_installer_factory.h"
namespace ci = common_installer;
+void WriteLog(ci::PkgMgrPtr pkgmgr, const char *msg) {
+ for (int i = 0; i < pkgmgr->GetRequestInfoCount(); i++) {
+ LOG(ERROR) << "Installer(" << i << ") " << msg << ": ["
+ << ci::GetRequestTypeString(pkgmgr->GetRequestType(i)) << "] "
+ << pkgmgr->GetRequestInfo(i);
+ }
+}
+
int main(int argc, char** argv) {
ci::PkgmgrInstaller installer;
try {
auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &installer);
+
ci::InstallerRunner runner(
std::make_unique<ci::UnifiedInstallerFactory>(), pkgmgr);
+
+ WriteLog(pkgmgr, "Start");
+
ci::AppInstaller::Result result = runner.Run();
+
+ WriteLog(pkgmgr, "Finish");
+
return (result == ci::AppInstaller::Result::OK) ? 0 : 1;
} catch(...) {
LOG(ERROR) << "Exception occured";
#include <libxml/xmlreader.h>
#include <unzip.h>
-#include <boost/filesystem/path.hpp>
-
#include <manifest_parser/utils/logging.h>
#include <hybrid/hybrid_installer.h>
#include <tpk/tpk_app_query_interface.h>
#include <wgt/utils/wgt_app_query_interface.h>
#include <wgt/wgt_installer.h>
+#include <filesystem>
#include <map>
#include <memory>
#include <string>
#include "common/pkgmgr_interface.h"
#include "common/utils/pkgmgr_query.h"
+namespace fs = std::filesystem;
+
namespace {
std::map<const char*, const char*> kTypeMap = {
std::string GetPkgTypeFromPath(const std::string& path) {
std::string type;
- if (boost::filesystem::extension(path) == ".rpk")
+ if (fs::path(path).extension() == ".rpk")
return "rpk";
unzFile uf = unzOpen(path.c_str());
return ValidatePkgType(type);
}
-std::string GetPkgTypeFromFilename(const boost::filesystem::path& name) {
+std::string GetPkgTypeFromFilename(const fs::path& name) {
std::string filename = name.string();
std::string token;
std::stringstream ss(filename);
std::string GetPkgTypeFromXml(const std::string& info, uid_t uid,
bool is_preload) {
- boost::filesystem::path xml_path =
- boost::filesystem::path(getUserManifestPath(uid, is_preload))
- / boost::filesystem::path(info);
+ fs::path xml_path =
+ fs::path(getUserManifestPath(uid, is_preload))
+ / fs::path(info);
xml_path += ".xml";
- if (!boost::filesystem::exists(xml_path)) {
+ if (!fs::exists(xml_path)) {
LOG(ERROR) << "xml path [" << xml_path << "] is not exist";
return "";
}
if (type.empty()) {
std::string file_name =
- (boost::filesystem::path(info).filename()).string();
+ (fs::path(info).filename()).string();
type = GetPkgTypeFromFilename(file_name);
if (type == file_name)
type.clear();
INSTALL(DIRECTORY test_samples/ DESTINATION ${SHAREDIR}/${DESTINATION_DIR}/test_samples)
APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST} PUBLIC
- Boost
GMOCK_DEPS
GUM_DEPS
)
APPLY_PKG_CONFIG(${TARGET_RECOVERY_TEST} PUBLIC
- Boost
GMOCK_DEPS
GUM_DEPS
)
-APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST_HELPER} PUBLIC
- Boost
-)
-
APPLY_PKG_CONFIG(${TARGET_DEPENDENCY_CHECKER_TEST} PUBLIC
- Boost
GMOCK_DEPS
)
#include <gtest/gtest.h>
+#include <filesystem>
+
#include "smoke_test/smoke_utils.h"
namespace ci = common_installer;
+namespace fs = std::filesystem;
namespace smoke_test {
ci::RequestMode request_mode_;
private:
- std::vector<bf::path> backups_;
+ std::vector<fs::path> backups_;
};
} // namespace smoke_test
std::list<AppInstallerPtr> installer_list_;
};
-const bf::path kUnifiedSmokePackagesDirectory =
+const fs::path kUnifiedSmokePackagesDirectory =
"/usr/share/unified-installer-ut/test_samples/smoke/";
class DependencyCheckerTest : public testing::Test {
};
TEST_F(DependencyCheckerTest, CircularDependency) {
- bf::path path1 = kUnifiedSmokePackagesDirectory / "smokedep01.tpk";
- bf::path path2 = kUnifiedSmokePackagesDirectory / "smokedep02.tpk";
- bf::path path3 = kUnifiedSmokePackagesDirectory / "smokedep03.tpk";
+ fs::path path1 = kUnifiedSmokePackagesDirectory / "smokedep01.tpk";
+ fs::path path2 = kUnifiedSmokePackagesDirectory / "smokedep02.tpk";
+ fs::path path3 = kUnifiedSmokePackagesDirectory / "smokedep03.tpk";
std::vector<std::string> pkgmgr_args =
{"", "-i", path1.string(), path2.string(), path3.string()};
}
TEST_F(DependencyCheckerTest, SortInstallRequest) {
- bf::path path4 = kUnifiedSmokePackagesDirectory / "smokedep04.tpk";
- bf::path path5 = kUnifiedSmokePackagesDirectory / "smokedep05.tpk";
- bf::path path6 = kUnifiedSmokePackagesDirectory / "smokedep06.tpk";
- bf::path path7 = kUnifiedSmokePackagesDirectory / "smokedep07.tpk";
- bf::path path8 = kUnifiedSmokePackagesDirectory / "smokedep08.tpk";
+ fs::path path4 = kUnifiedSmokePackagesDirectory / "smokedep04.tpk";
+ fs::path path5 = kUnifiedSmokePackagesDirectory / "smokedep05.tpk";
+ fs::path path6 = kUnifiedSmokePackagesDirectory / "smokedep06.tpk";
+ fs::path path7 = kUnifiedSmokePackagesDirectory / "smokedep07.tpk";
+ fs::path path8 = kUnifiedSmokePackagesDirectory / "smokedep08.tpk";
std::vector<std::string> pkgmgr_args = {"", "-i", path4.string(),
path5.string(), path6.string(), path7.string(), path8.string()};
}
TEST_F(DependencyCheckerTest, SortUninstallRequest) {
- bf::path path4 = kUnifiedSmokePackagesDirectory / "smokedep04.tpk";
- bf::path path5 = kUnifiedSmokePackagesDirectory / "smokedep05.tpk";
- bf::path path6 = kUnifiedSmokePackagesDirectory / "smokedep06.tpk";
- bf::path path7 = kUnifiedSmokePackagesDirectory / "smokedep07.tpk";
- bf::path path8 = kUnifiedSmokePackagesDirectory / "smokedep08.tpk";
+ fs::path path4 = kUnifiedSmokePackagesDirectory / "smokedep04.tpk";
+ fs::path path5 = kUnifiedSmokePackagesDirectory / "smokedep05.tpk";
+ fs::path path6 = kUnifiedSmokePackagesDirectory / "smokedep06.tpk";
+ fs::path path7 = kUnifiedSmokePackagesDirectory / "smokedep07.tpk";
+ fs::path path8 = kUnifiedSmokePackagesDirectory / "smokedep08.tpk";
std::string pkg4 = "smokedep04";
std::string pkg5 = "smokedep05";
std::string pkg7 = "smokedep07";
std::string pkg8 = "smokedep08";
- std::vector<bf::path> install_args = {path4, path5, path6, path7, path8};
+ std::vector<fs::path> install_args = {path4, path5, path6, path7, path8};
ASSERT_EQ(backend.Install(install_args), ci::AppInstaller::Result::OK);
std::vector<std::string> pkgmgr_args = {"", "-d", "smokedep04",
}
TEST_F(DependencyCheckerTest, InvalidDependency_RequiredPkgNotExist) {
- bf::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
+ fs::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
std::vector<std::string> pkgmgr_args = {"", "-i", path9.string()};
TestPkgmgrInstaller pkgmgr_installer;
}
TEST_F(DependencyCheckerTest, InvalidDependency_RequiredPkgVersionLow) {
- bf::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
- bf::path path10 = kUnifiedSmokePackagesDirectory / "smokedep10-1.0.0.tpk";
+ fs::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
+ fs::path path10 = kUnifiedSmokePackagesDirectory / "smokedep10-1.0.0.tpk";
ASSERT_EQ(backend.Install(path10), ci::AppInstaller::Result::OK);
}
TEST_F(DependencyCheckerTest, InvalidDependency_RequiredPkgVersionDown_1) {
- bf::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
- bf::path path10_1 = kUnifiedSmokePackagesDirectory / "smokedep10-1.0.0.tpk";
- bf::path path10_2 = kUnifiedSmokePackagesDirectory / "smokedep10-2.0.0.tpk";
+ fs::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
+ fs::path path10_1 = kUnifiedSmokePackagesDirectory / "smokedep10-1.0.0.tpk";
+ fs::path path10_2 = kUnifiedSmokePackagesDirectory / "smokedep10-2.0.0.tpk";
- ASSERT_EQ(backend.Install(std::vector<bf::path>({path9, path10_2})),
+ ASSERT_EQ(backend.Install(std::vector<fs::path>({path9, path10_2})),
ci::AppInstaller::Result::OK);
std::vector<std::string> pkgmgr_args = {"", "-i", path10_1.string()};
}
TEST_F(DependencyCheckerTest, InvalidDependency_RequiredPkgVersionDown_2) {
- bf::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
- bf::path path10_1 = kUnifiedSmokePackagesDirectory / "smokedep10-1.0.0.tpk";
- bf::path path10_2 = kUnifiedSmokePackagesDirectory / "smokedep10-2.0.0.tpk";
+ fs::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
+ fs::path path10_1 = kUnifiedSmokePackagesDirectory / "smokedep10-1.0.0.tpk";
+ fs::path path10_2 = kUnifiedSmokePackagesDirectory / "smokedep10-2.0.0.tpk";
std::string pkgid10 = "smokedep10";
ASSERT_EQ(backend.InstallPreload(path10_1), ci::AppInstaller::Result::OK);
- ASSERT_EQ(backend.Install(std::vector<bf::path>({path9, path10_2})),
+ ASSERT_EQ(backend.Install(std::vector<fs::path>({path9, path10_2})),
ci::AppInstaller::Result::OK);
std::vector<std::string> pkgmgr_args = {"", "-d", pkgid10};
}
TEST_F(DependencyCheckerTest, InvalidDependency_RequiredPkgUninstall) {
- bf::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
- bf::path path10_2 = kUnifiedSmokePackagesDirectory / "smokedep10-2.0.0.tpk";
+ fs::path path9 = kUnifiedSmokePackagesDirectory / "smokedep09.tpk";
+ fs::path path10_2 = kUnifiedSmokePackagesDirectory / "smokedep10-2.0.0.tpk";
std::string pkgid10 = "smokedep10";
- ASSERT_EQ(backend.Install(std::vector<bf::path>({path9, path10_2})),
+ ASSERT_EQ(backend.Install(std::vector<fs::path>({path9, path10_2})),
ci::AppInstaller::Result::OK);
std::vector<std::string> pkgmgr_args = {"", "-d", pkgid10};
#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
+#include <filesystem>
+
#include "smoke_test/smoke_utils.h"
namespace ci = common_installer;
+namespace fs = std::filesystem;
namespace smoke_test {
private:
ci::RequestMode request_mode_;
- std::vector<bf::path> backups_;
+ std::vector<fs::path> backups_;
};
} // namespace smoke_test
namespace smoke_test {
-const bf::path kUnifiedSmokePackagesDirectory =
+const fs::path kUnifiedSmokePackagesDirectory =
"/usr/share/unified-installer-ut/test_samples/smoke/";
class SmokeTest : public testing::Test {
};
TEST_F(SmokeTest, Install_Single) {
- bf::path path =
+ fs::path path =
kUnifiedSmokePackagesDirectory / "Install_SingleTpk.tpk";
std::string pkgid = "smokeuni01";
std::string appid = "smokeuni01.InstallSingleTpk";
std::string exec = "smokeunified";
- std::vector<bf::path> paths = { path };
+ std::vector<fs::path> paths = { path };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
}
TEST_F(SmokeTest, Install_Double) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "Install_DoubleTpk.tpk";
std::string pkgid1 = "smokeuni02";
std::string appid1 = "smokeuni02.InstallDoubleTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "Install_DoubleWgt.wgt";
std::string pkgid2 = "smokeuni03";
std::string appid2 = "smokeuni03.InstallDoubleWgt";
std::string exec2 = "smokeuni03.InstallDoubleWgt";
- std::vector<bf::path> paths = { path1, path2 };
+ std::vector<fs::path> paths = { path1, path2 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
}
TEST_F(SmokeTest, Install_Triple) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "Install_TripleTpk.tpk";
std::string pkgid1 = "smokeuni04";
std::string appid1 = "smokeuni04.InstallTripleTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "Install_TripleWgt.wgt";
std::string pkgid2 = "smokeuni05";
std::string appid2 = "smokeuni05.InstallTripleWgt";
std::string exec2 = "smokeuni05.InstallTripleWgt";
- bf::path path3 =
+ fs::path path3 =
kUnifiedSmokePackagesDirectory / "Install_TripleHybrid.wgt";
std::string pkgid3 = "smokeuni06";
std::string appid3 = "smokeuni06.InstallTripleHybrid";
std::string exec3 = "smokeuni06.InstallTripleHybrid";
- std::vector<bf::path> paths = { path1, path2, path3 };
+ std::vector<fs::path> paths = { path1, path2, path3 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
}
TEST_F(SmokeTest, Update_Single) {
- bf::path path_old =
+ fs::path path_old =
kUnifiedSmokePackagesDirectory / "Update_SingleTpk.tpk";
- bf::path path_new =
+ fs::path path_new =
kUnifiedSmokePackagesDirectory / "Update_SingleTpk_2.tpk";
std::string pkgid = "smokeuni07";
std::string appid = "smokeuni07.UpdateSingleTpk";
std::string exec = "smokeunified";
- std::vector<bf::path> paths = { path_old };
+ std::vector<fs::path> paths = { path_old };
// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
paths = { path_new };
}
TEST_F(SmokeTest, Update_Double) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "Update_DoubleTpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory / "Update_DoubleTpk_2.tpk";
std::string pkgid1 = "smokeuni08";
std::string appid1 = "smokeuni08.UpdateDoubleTpk";
std::string exec1 = "smokeunified";
- bf::path path2_old =
+ fs::path path2_old =
kUnifiedSmokePackagesDirectory / "Update_DoubleWgt.wgt";
- bf::path path2_new =
+ fs::path path2_new =
kUnifiedSmokePackagesDirectory / "Update_DoubleWgt_2.wgt";
std::string pkgid2 = "smokeuni09";
std::string appid2 = "smokeuni09.UpdateDoubleWgt";
std::string exec2 = "smokeuni09.UpdateDoubleWgt";
- std::vector<bf::path> paths = { path1_old, path2_old };
+ std::vector<fs::path> paths = { path1_old, path2_old };
// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
paths = { path1_new, path2_new };
}
TEST_F(SmokeTest, Update_Triple) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "Update_TripleTpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory / "Update_TripleTpk_2.tpk";
std::string pkgid1 = "smokeuni10";
std::string appid1 = "smokeuni10.UpdateTripleTpk";
std::string exec1 = "smokeunified";
- bf::path path2_old =
+ fs::path path2_old =
kUnifiedSmokePackagesDirectory / "Update_TripleWgt.wgt";
- bf::path path2_new =
+ fs::path path2_new =
kUnifiedSmokePackagesDirectory / "Update_TripleWgt_2.wgt";
std::string pkgid2 = "smokeuni11";
std::string appid2 = "smokeuni11.UpdateTripleWgt";
std::string exec2 = "smokeuni11.UpdateTripleWgt";
- bf::path path3_old =
+ fs::path path3_old =
kUnifiedSmokePackagesDirectory / "Update_TripleHybrid.wgt";
- bf::path path3_new =
+ fs::path path3_new =
kUnifiedSmokePackagesDirectory / "Update_TripleHybrid_2.wgt";
std::string pkgid3 = "smokeuni12";
std::string appid3 = "smokeuni12.UpdateTripleHybrid";
std::string exec3 = "smokeuni12.UpdateTripleHybrid";
- std::vector<bf::path> paths = { path1_old, path2_old, path3_old };
+ std::vector<fs::path> paths = { path1_old, path2_old, path3_old };
// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
paths = { path1_new, path2_new, path3_new };
}
TEST_F(SmokeTest, InstallAndUpdate) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk_2.tpk";
std::string pkgid1 = "smokeuni13";
std::string appid1 = "smokeuni13.InstallAndUpdateModeTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Wgt.wgt";
std::string pkgid2 = "smokeuni14";
std::string appid2 = "smokeuni14.InstallAndUpdateWgt";
std::string exec2 = "smokeuni14.InstallAndUpdateWgt";
// install tpk version 1
- std::vector<bf::path> paths = { path1_old };
+ std::vector<fs::path> paths = { path1_old };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
// update tpk version 2, install wgt version 1
paths = { path1_new, path2 };
}
TEST_F(SmokeTest, InstallAndROUpdate) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Tpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Tpk_2.tpk";
std::string pkgid1 = "smokeuni25";
std::string appid1 = "smokeuni25.InstallAndROUpdateModeTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Wgt.wgt";
std::string pkgid2 = "smokeuni26";
std::string appid2 = "smokeuni26.InstallAndROUpdateWgt";
// install tpk version 1
ASSERT_EQ(backend.InstallPreload(path1_old), ci::AppInstaller::Result::OK);
// update tpk version 2, install wgt version 1
- std::vector<bf::path> paths = { path1_new, path2 };
+ std::vector<fs::path> paths = { path1_new, path2 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
}
TEST_F(SmokeTest, Uninstall_Single) {
- bf::path path =
+ fs::path path =
kUnifiedSmokePackagesDirectory / "Uninstall_SingleTpk.tpk";
std::string pkgid = "smokeuni29";
std::string appid = "smokeuni29.UninstallSingleTpk";
std::string exec = "smokeunified";
- std::vector<bf::path> paths = { path };
+ std::vector<fs::path> paths = { path };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
}
TEST_F(SmokeTest, Uninstall_Double) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "Uninstall_DoubleTpk.tpk";
std::string pkgid1 = "smokeuni30";
std::string appid1 = "smokeuni30.UninstallDoubleTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "Uninstall_DoubleWgt.wgt";
std::string pkgid2 = "smokeuni31";
std::string appid2 = "smokeuni31.UninstallDoubleWgt";
std::string exec2 = "smokeuni31.UninstallDoubleWgt";
- std::vector<bf::path> paths = { path1, path2 };
+ std::vector<fs::path> paths = { path1, path2 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
}
TEST_F(SmokeTest, Uninstall_Triple) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "Uninstall_TripleTpk.tpk";
std::string pkgid1 = "smokeuni32";
std::string appid1 = "smokeuni32.UninstallTripleTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "Uninstall_TripleWgt.wgt";
std::string pkgid2 = "smokeuni33";
std::string appid2 = "smokeuni33.UninstallTripleWgt";
std::string exec2 = "smokeuni33.UninstallTripleWgt";
- bf::path path3 =
+ fs::path path3 =
kUnifiedSmokePackagesDirectory / "Uninstall_TripleHybrid.wgt";
std::string pkgid3 = "smokeuni34";
std::string appid3 = "smokeuni34.UninstallTripleHybrid";
std::string exec3 = "smokeuni34.UninstallTripleHybrid";
- std::vector<bf::path> paths = { path1, path2, path3 };
+ std::vector<fs::path> paths = { path1, path2, path3 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
}
TEST_F(SmokeTest, UninstallAndROUpdateUninstall) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "UninstallAndROUpdateUninstall_Tpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory /
"UninstallAndROUpdateUninstall_Tpk_2.tpk";
std::string pkgid1 = "smokeuni35";
std::string appid1 = "smokeuni35.UninstallAndROUpdateUninstallTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "UninstallAndROUpdateUninstall_Wgt.wgt";
std::string pkgid2 = "smokeuni36";
std::string appid2 = "smokeuni36.UninstallAndROUpdateUninstallWgt";
ci::PkgQueryInterface pkg_query1(pkgid1, params.test_user.uid);
PackageAttributes original(pkg_query1);
// update tpk version 2, install wgt version 1
- std::vector<bf::path> paths = { path1_new, path2 };
+ std::vector<fs::path> paths = { path1_new, path2 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
};
TEST_F(RollbackSmokeTest, Install_Rollback) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "Install_RollbackTpk.tpk";
std::string pkgid1 = "smokeuni15";
std::string appid1 = "smokeuni15.InstallRollbackTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "Install_RollbackWgt.wgt";
std::string pkgid2 = "smokeuni16";
std::string appid2 = "smokeuni16.InstallRollbackWgt";
std::string exec2 = "smokeuni16.InstallRollbackWgt";
- std::vector<bf::path> paths = { path1, path2 };
+ std::vector<fs::path> paths = { path1, path2 };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
}
TEST_F(RollbackSmokeTest, Update_Rollback) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "Update_RollbackTpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory / "Update_RollbackTpk_2.tpk";
std::string pkgid1 = "smokeuni17";
std::string appid1 = "smokeuni17.UpdateRollbackTpk";
std::string exec1 = "smokeunified";
- bf::path path2_old =
+ fs::path path2_old =
kUnifiedSmokePackagesDirectory / "Update_RollbackWgt.wgt";
- bf::path path2_new =
+ fs::path path2_new =
kUnifiedSmokePackagesDirectory / "Update_RollbackWgt_2.wgt";
std::string pkgid2 = "smokeuni18";
std::string appid2 = "smokeuni18.UpdateRollbackWgt";
std::string exec2 = "smokeuni18.UpdateRollbackWgt";
- std::vector<bf::path> paths = { path1_old, path2_old };
+ std::vector<fs::path> paths = { path1_old, path2_old };
ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
paths = { path1_new, path2_new };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
}
TEST_F(RollbackSmokeTest, InstallAndUpdate_Rollback) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackTpk.tpk";
std::string pkgid1 = "smokeuni19";
std::string appid1 = "smokeuni19.InstallAndUpdateRollbackTpk";
std::string exec1 = "smokeunified";
- bf::path path2_old =
+ fs::path path2_old =
kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt.wgt";
- bf::path path2_new =
+ fs::path path2_new =
kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt_2.wgt";
std::string pkgid2 = "smokeuni20";
std::string appid2 = "smokeuni20.InstallAndUpdateRollbackWgt";
std::string exec2 = "smokeuni20.InstallAndUpdateRollbackWgt";
- std::vector<bf::path> paths = { path2_old };
+ std::vector<fs::path> paths = { path2_old };
ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
// pkgid1: install, pkgid2: update
paths = { path1, path2_new };
}
TEST_F(RollbackSmokeTest, InstallAndROUpdate_Rollback) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackTpk.tpk";
std::string pkgid1 = "smokeuni27";
std::string appid1 = "smokeuni27.InstallAndROUpdateRollbackTpk";
std::string exec1 = "smokeunified";
- bf::path path2_old =
+ fs::path path2_old =
kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackWgt.wgt";
- bf::path path2_new =
+ fs::path path2_new =
kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackWgt_2.wgt";
std::string pkgid2 = "smokeuni28";
std::string appid2 = "smokeuni28.InstallAndROUpdateRollbackWgt";
ASSERT_EQ(backend.InstallPreloadSuccess(path2_old),
ci::AppInstaller::Result::OK);
// pkgid1: install, pkgid2: update
- std::vector<bf::path> paths = { path1, path2_new };
+ std::vector<fs::path> paths = { path1, path2_new };
ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
}
TEST_F(SmokeTest, Recovery_Install) {
- bf::path path1 =
+ fs::path path1 =
kUnifiedSmokePackagesDirectory / "Recovery_InstallTpk.tpk";
std::string pkgid1 = "smokeuni21";
std::string appid1 = "smokeuni21.RecoveryInstallTpk";
std::string exec1 = "smokeunified";
- bf::path path2 =
+ fs::path path2 =
kUnifiedSmokePackagesDirectory / "Recovery_InstallWgt.wgt";
std::string pkgid2 = "smokeuni22";
std::string appid2 = "smokeuni22.RecoveryInstallWgt";
backend_crash.Run(argv);
ASSERT_NE(backend_crash.Wait(), 0);
- bf::path recovery_file =
+ fs::path recovery_file =
FindRecoveryFile("/tpk-recovery", params.test_user.uid);
ASSERT_FALSE(recovery_file.empty());
std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::TPK;
ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+ ASSERT_FALSE(fs::exists(recovery_info->unpacked_dir()));
recovery_file =
FindRecoveryFile("/wgt-recovery", params.test_user.uid);
ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
params.pkg_type = PackageType::WGT;
ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
- ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+ ASSERT_FALSE(fs::exists(recovery_info->unpacked_dir()));
}
TEST_F(SmokeTest, Recovery_Update) {
- bf::path path1_old =
+ fs::path path1_old =
kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk.tpk";
- bf::path path1_new =
+ fs::path path1_new =
kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk_2.tpk";
std::string pkgid1 = "smokeuni23";
std::string appid1 = "smokeuni23.RecoveryUpdateTpk";
std::string exec1 = "smokeunified";
- bf::path path2_old =
+ fs::path path2_old =
kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt.wgt";
- bf::path path2_new =
+ fs::path path2_new =
kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt_2.wgt";
std::string pkgid2 = "smokeuni24";
std::string appid2 = "smokeuni24.RecoveryUpdateWgt";
std::string exec2 = "smokeuni24.RecoveryUpdateWgt";
- std::vector<bf::path> paths_old = { path1_old, path2_old };
+ std::vector<fs::path> paths_old = { path1_old, path2_old };
ASSERT_EQ(backend.Install(paths_old), ci::AppInstaller::Result::OK);
std::vector<std::string> paths = { path1_new.string(), path2_new.string() };
backend_crash.Run(argv);
ASSERT_NE(backend_crash.Wait(), 0);
- bf::path recovery_file =
+ fs::path recovery_file =
FindRecoveryFile("/tpk-recovery", params.test_user.uid);
ASSERT_FALSE(recovery_file.empty());
std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
#include <smoke_tests/wgt_smoke_utils.h>
#include <unzip.h>
+#include <filesystem>
#include <map>
#include <string>
#include <vector>
-namespace bf = boost::filesystem;
namespace ci = common_installer;
+namespace fs = std::filesystem;
namespace {
}
std::string GetPkgTypeFromRecoveryFile(const std::string& path) {
- bf::path recovery_file = path;
+ fs::path recovery_file = path;
if (recovery_file.filename().string().find("tpk") == 0)
return "tpk";
else if (recovery_file.filename().string().find("wgt") == 0)
"/usr/bin/unified-installer-ut/smoke-test-helper");
}
-UnifiedRecoveryInfo::UnifiedRecoveryInfo(bf::path path) : path_(path) {
+UnifiedRecoveryInfo::UnifiedRecoveryInfo(fs::path path) : path_(path) {
}
bool UnifiedRecoveryInfo::Init() {
break;
}
- if (!boost::filesystem::exists(line_data))
+ if (!fs::exists(line_data))
continue;
recovery_files_.emplace_back(line_data);
return clean_up_;
}
-const std::vector<bf::path> UnifiedRecoveryInfo::GetRecoveryFiles() const {
+const std::vector<fs::path> UnifiedRecoveryInfo::GetRecoveryFiles() const {
return recovery_files_;
}
#include <smoke_tests/common/smoke_utils.h>
#include <smoke_tests/tpk_smoke_utils.h>
+#include <filesystem>
#include <string>
#include <vector>
-#include <boost/filesystem/path.hpp>
-
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
namespace smoke_test {
class UnifiedRecoveryInfo {
public:
- explicit UnifiedRecoveryInfo(bf::path path);
+ explicit UnifiedRecoveryInfo(fs::path path);
bool Init();
bool GetCleanUp() const;
- const std::vector<bf::path> GetRecoveryFiles() const;
+ const std::vector<fs::path> GetRecoveryFiles() const;
private:
- std::vector<bf::path> recovery_files_;
- bf::path path_;
+ std::vector<fs::path> recovery_files_;
+ fs::path path_;
bool clean_up_ = false;
};
// Use of this source code is governed by an apache-2.0 license that can be
// found in the LICENSE file.
-#include <boost/exception/diagnostic_information.hpp>
-#include <boost/program_options.hpp>
-
#include <common/utils/subprocess.h>
#include <smoke_tests/common/smoke_utils.h>
+#include <getopt.h>
#include <gtest/gtest.h>
#include <map>
#include "smoke_test/smoke_utils.h"
-namespace bf = boost::filesystem;
-namespace bpo = boost::program_options;
namespace ci = common_installer;
+namespace bf = std::filesystem;
enum class ReqType : int {
UNKNOWN_REQ,
private:
ci::RequestMode request_mode_;
- std::vector<bf::path> backups_;
+ std::vector<fs::path> backups_;
bool no_backup_;
BackupType backup_type_;
};
namespace smoke_test {
-const bf::path kUnifiedSmokePackagesDirectory =
+const fs::path kUnifiedSmokePackagesDirectory =
"/usr/share/unified-installer-ut/test_samples/smoke/";
class SmokeTest : public testing::Test {
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
- std::vector<bf::path> paths = {
+ std::vector<fs::path> paths = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
}
ASSERT_EQ(ret, BackendInterface::SubProcessResult::KILLED);
- bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ fs::path recovery_file = FindRecoveryFile("/unified-recovery",
params.test_user.uid);
if (recovery_file.empty()) {
std::cout << "recovery file dosen't exist, "
UnifiedRecoveryInfo recovery_info(recovery_file);
ASSERT_TRUE(recovery_info.Init());
- bf::remove(recovery_file);
- const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ fs::remove(recovery_file);
+ const std::vector<fs::path>& recovery_list = recovery_info.GetRecoveryFiles();
if (recovery_list.empty()) {
std::cout << "installer recovery file is not created yet" << std::endl;
return;
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
- std::vector<bf::path> paths_old = {
+ std::vector<fs::path> paths_old = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
- std::vector<bf::path> paths_new = {
+ std::vector<fs::path> paths_new = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg2.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg2.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg2.wgt" };
}
ASSERT_EQ(ret, BackendInterface::SubProcessResult::KILLED);
- bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ fs::path recovery_file = FindRecoveryFile("/unified-recovery",
params.test_user.uid);
if (recovery_file.empty()) {
std::cout << "recovery file dosen't exist, "
UnifiedRecoveryInfo recovery_info(recovery_file);
ASSERT_TRUE(recovery_info.Init());
- bf::remove(recovery_file);
- const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ fs::remove(recovery_file);
+ const std::vector<fs::path>& recovery_list = recovery_info.GetRecoveryFiles();
if (recovery_list.empty()) {
std::cout << "installer recovery file is not created yet" << std::endl;
return;
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
- std::vector<bf::path> paths_old = {
+ std::vector<fs::path> paths_old = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
- std::vector<bf::path> paths_new = {
+ std::vector<fs::path> paths_new = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.delta",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.delta",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.delta" };
}
ASSERT_EQ(ret, BackendInterface::SubProcessResult::KILLED);
- bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ fs::path recovery_file = FindRecoveryFile("/unified-recovery",
params.test_user.uid);
if (recovery_file.empty()) {
std::cout << "recovery file dosen't exist, "
UnifiedRecoveryInfo recovery_info(recovery_file);
ASSERT_TRUE(recovery_info.Init());
- bf::remove(recovery_file);
- const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ fs::remove(recovery_file);
+ const std::vector<fs::path>& recovery_list = recovery_info.GetRecoveryFiles();
if (recovery_list.empty()) {
std::cout << "installer recovery file is not created yet" << std::endl;
return;
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
- std::vector<bf::path> paths = {
+ std::vector<fs::path> paths = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
}
ASSERT_EQ(ret, BackendInterface::SubProcessResult::KILLED);
- bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ fs::path recovery_file = FindRecoveryFile("/unified-recovery",
params.test_user.uid);
if (recovery_file.empty()) {
std::cout << "recovery file dosen't exist, "
UnifiedRecoveryInfo recovery_info(recovery_file);
ASSERT_TRUE(recovery_info.Init());
- bf::remove(recovery_file);
- const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ fs::remove(recovery_file);
+ const std::vector<fs::path>& recovery_list = recovery_info.GetRecoveryFiles();
if (recovery_list.empty()) {
std::cout << "installer recovery file is not created yet" << std::endl;
return;
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
- std::vector<bf::path> paths_old = {
+ std::vector<fs::path> paths_old = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
- std::vector<bf::path> paths_new = {
+ std::vector<fs::path> paths_new = {
kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg2.tpk",
kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg2.wgt",
kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg2.wgt" };
}
ASSERT_EQ(ret, BackendInterface::SubProcessResult::KILLED);
- bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ fs::path recovery_file = FindRecoveryFile("/unified-recovery",
params.test_user.uid);
if (recovery_file.empty()) {
std::cout << "recovery file dosen't exist, "
UnifiedRecoveryInfo recovery_info(recovery_file);
ASSERT_TRUE(recovery_info.Init());
- bf::remove(recovery_file);
- const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ fs::remove(recovery_file);
+ const std::vector<fs::path>& recovery_list = recovery_info.GetRecoveryFiles();
if (recovery_list.empty()) {
std::cout << "installer recovery file is not created yet" << std::endl;
return;
} // namespace smoke_test
const int kBufSize = 1024;
+const struct option long_opts[] = {
+ { "help", no_argument, nullptr, 'h' },
+ { "install", no_argument, nullptr, 'i' },
+ { "update", no_argument, nullptr, 'u' },
+ { "delta", no_argument, nullptr, 'D' },
+ { "mount-install", no_argument, nullptr,'m' },
+ { "mount-update", no_argument, nullptr, 'M' },
+ { "delay", required_argument, nullptr, 't' },
+ { "interval", required_argument, nullptr, 'I' },
+ { "repeat", required_argument, nullptr, 'r' },
+ { "no-backup", no_argument, nullptr, 'n' },
+ { "backup-type", required_argument, nullptr, 'b' },
+ { 0, 0, 0, 0 }
+};
+
+const char kHelpMessage[] = R"(Allowed options:
+ --help display this help message
+ --install recovery test for forced termination during package
+ installing
+ --update recovery test for forced termination during package
+ updating
+ --delta recovery test for forced termination during package
+ delta installing
+ --mount-install recovery test for forced termination during package
+ mount-installing
+ --mount-update recovery test for forced termination during package
+ mount-updating
+ --delay arg fixed delay for forced termination
+ unit : microsecond (ex. 1000000us = 1s)
+ --interval arg use with repeat option.
+ as it repeat the interval is added to delay
+ unit : microsecond (ex. 1000000us = 1s)
+ --repeat arg option for performing tests repeatedly
+ enter -1 to test infinitely
+ --no-backup Do test without backup
+ --backup-type arg <move|copy> set test's backup type 'move', 'copy and
+ remove'
+)";
+
+void PrintHelp() {
+ std::cerr << kHelpMessage;
+}
int main(int argc, char** argv) {
try {
if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL)
std::cout << "Run recovery test with user request mode" << std::endl;
- bpo::options_description options("Allowed options");
- bpo::variables_map opt_map;
- options.add_options()
- ("help", "display this help message")
- ("install",
- "recovery test for forced termination "
- "during package installing")
- ("update",
- "recovery test for forced termination "
- "during package updating")
- ("delta",
- "recovery test for forced termination "
- "during package delta installing")
- ("mount-install",
- "recovery test for forced termination "
- "during package mount-installing")
- ("mount-update",
- "recovery test for forced termination "
- "during package mount-updating")
- ("delay", bpo::value<int>(), "fixed delay for forced termination\n"
- "unit : microsecond (ex. 1000000us = 1s)")
- ("interval", bpo::value<int>(),
- "use with repeat option.\n"
- "as it repeat the interval is added to delay\n"
- "unit : microsecond (ex. 1000000us = 1s)")
- ("repeat", bpo::value<int>(), "option for performing tests repeatedly\n"
- "enter -1 to test infinitely")
- ("no-backup", "Do test without backup")
- ("backup-type", bpo::value<std::string>(), "<move|copy> set test's "
- "backup type \'move\', \'copy and remove\'");
- bpo::store(bpo::command_line_parser(argc, argv).
- options(options).allow_unregistered().run(), opt_map);
- if (opt_map.count("help")) {
- std::cerr << options << std::endl;
- return -1;
- }
-
- if (opt_map.count("install"))
- req_type = ReqType::INSTALL_REQ;
- else if (opt_map.count("update"))
- req_type = ReqType::UPDATE_REQ;
- else if (opt_map.count("delta"))
- req_type = ReqType::DELTA_REQ;
- else if (opt_map.count("mount-install"))
- req_type = ReqType::MOUNT_INSTALL_REQ;
- else if (opt_map.count("mount-update"))
- req_type = ReqType::MOUNT_UPDATE_REQ;
-
- if (opt_map.count("delay"))
- delay = opt_map["delay"].as<int>();
-
- if (opt_map.count("interval"))
- interval = opt_map["interval"].as<int>();
-
- if (opt_map.count("repeat")) {
- repeat = true;
- repeat_count = opt_map["repeat"].as<int>();
- }
-
- if (opt_map.count("no-backup"))
- no_backup = true;
- if (opt_map.count("backup-type")) {
- if (opt_map["backup-type"].as<std::string>() == "move") {
- backup_type = BackupType::MOVE;
- } else if (opt_map["backup-type"].as<std::string>() == "copy") {
- backup_type = BackupType::COPY_AND_REMOVE;
- } else {
- std::cerr << options << std::endl;
- return -1;
+ while (true) {
+ int opt = getopt_long(argc, argv, "", long_opts, nullptr);
+ if (opt == -1)
+ break;
+ switch (opt) {
+ case 'h':
+ PrintHelp();
+ return -1;
+ case 'i':
+ req_type = ReqType::INSTALL_REQ;
+ break;
+ case 'u':
+ req_type = ReqType::UPDATE_REQ;
+ break;
+ case 'D':
+ req_type = ReqType::DELTA_REQ;
+ break;
+ case 'm':
+ req_type = ReqType::MOUNT_INSTALL_REQ;
+ break;
+ case 'M':
+ req_type = ReqType::MOUNT_UPDATE_REQ;
+ break;
+ case 't':
+ if (optarg)
+ delay = std::stoi(optarg);
+ break;
+ case 'I':
+ if (optarg)
+ interval = std::stoi(optarg);
+ break;
+ case 'r':
+ if (optarg) {
+ repeat = true;
+ repeat_count = std::stoi(optarg);
+ }
+ break;
+ case 'n':
+ no_backup = true;
+ break;
+ case 'b':
+ if (optarg) {
+ if (strncmp(optarg, "move", strlen("move")) == 0) {
+ backup_type = BackupType::MOVE;
+ } else if (strncmp(optarg, "copy", strlen("copy")) == 0) {
+ backup_type = BackupType::COPY_AND_REMOVE;
+ } else {
+ PrintHelp();
+ return -1;
+ }
+ }
+ break;
+ default:
+ PrintHelp();
+ return -1;
}
}
- bpo::notify(opt_map);
if (req_type == ReqType::UNKNOWN_REQ) {
- std::cerr << options << std::endl;
+ PrintHelp();
return 0;
}