From: Sangyoon Jang Date: Tue, 20 Dec 2022 06:05:31 +0000 (+0900) Subject: Add ROU to RW case to pkg_upgrade X-Git-Tag: accepted/tizen/7.0/unified/20230705.171221~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c2f6e18b6cb911186fe66067cc0c466921078d65;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Add ROU to RW case to pkg_upgrade old_pkg: RO updated pkg new_pkg: RO removed, only RW remained Change-Id: I51e820e96fa6eed18bff0561565f446cf4699059 Signed-off-by: Sangyoon Jang --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 9422904..af1e541 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser) PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info) PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer) PKG_CHECK_MODULES(INIPARSER_DEPS REQUIRED iniparser) +PKG_CHECK_MODULES(TIZEN_DATABASE_DEPS REQUIRED tizen-database) PKG_CHECK_MODULES(TZPLATFORM_DEPS REQUIRED libtzplatform-config) PKG_CHECK_MODULES(AUL_DEPS REQUIRED aul) PKG_CHECK_MODULES(STORAGE_DEPS REQUIRED storage) @@ -46,7 +47,7 @@ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs -pie" ) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -Wall -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Werror -ffunction-sections -fdata-sections -fmerge-all-constants -fPIE") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Werror -ffunction-sections -fdata-sections -fmerge-all-constants -fPIE") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -fPIE") SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIE") diff --git a/packaging/pkgmgr-tool.spec b/packaging/pkgmgr-tool.spec index 478aaa2..5c37861 100644 --- a/packaging/pkgmgr-tool.spec +++ b/packaging/pkgmgr-tool.spec @@ -29,6 +29,7 @@ BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(storage) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(gmock) +BuildRequires: tizen-database-devel BuildRequires: pkgmgr-info-parser-devel BuildRequires: pkgmgr-info-parser BuildRequires: fdupes diff --git a/src/pkg_upgrade/CMakeLists.txt b/src/pkg_upgrade/CMakeLists.txt index 581b7ae..f5b621f 100755 --- a/src/pkg_upgrade/CMakeLists.txt +++ b/src/pkg_upgrade/CMakeLists.txt @@ -9,6 +9,7 @@ ADD_EXECUTABLE(${TARGET_PKG_UPGRADE} ${SRCS}) APPLY_PKG_CONFIG(${TARGET_PKG_UPGRADE} PUBLIC PKGMGR_INFO_DEPS PKGMGR_PARSER_DEPS + TIZEN_DATABASE_DEPS TZPLATFORM_DEPS SMACK_DEPS DLOG_DEPS @@ -17,4 +18,3 @@ APPLY_PKG_CONFIG(${TARGET_PKG_UPGRADE} PUBLIC # Install INSTALL(TARGETS ${TARGET_PKG_UPGRADE} DESTINATION bin) - diff --git a/src/pkg_upgrade/include/common_type.hh b/src/pkg_upgrade/include/common_type.hh index 9ebbc89..05a7598 100644 --- a/src/pkg_upgrade/include/common_type.hh +++ b/src/pkg_upgrade/include/common_type.hh @@ -53,9 +53,10 @@ enum class PkgVersionCmpResult { class PkgContext { public: PkgContext(std::string id, std::string version, std::string type, - bool read_only, bool removable = false) + bool read_only, bool update = false, bool removable = false) : id_(std::move(id)), version_(std::move(version)), - type_(std::move(type)), read_only_(read_only), removable_(removable) { + type_(std::move(type)), read_only_(read_only), update_(update), + removable_(removable) { if (read_only) removable_ = false; } @@ -75,6 +76,7 @@ class PkgContext { return PkgLocation::RW; } bool IsReadOnly() const { return read_only_; } + bool IsUpdate() const { return update_; } bool IsRemovable() const { return removable_; } private: @@ -82,6 +84,7 @@ class PkgContext { std::string version_; std::string type_; bool read_only_; + bool update_; // update means ReadonlyUpdated pkg bool removable_; }; diff --git a/src/pkg_upgrade/include/db_upgrader.hh b/src/pkg_upgrade/include/db_upgrader.hh new file mode 100644 index 0000000..8b82f62 --- /dev/null +++ b/src/pkg_upgrade/include/db_upgrader.hh @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DB_UPGRADER_HH_ +#define DB_UPGRADER_HH_ + +#include + +#include "pkg_upgrader.hh" + +namespace common_fota { + +class DbUpgrader : public PkgUpgrader { + public: + DbUpgrader(const PkgContext& context, PkgOperation pkg_op); + virtual ~DbUpgrader() = default; + bool Upgrade() override; + + bool SetRwPkg(const std::string& pkgid); + + private: + std::string pkgid_; +}; + +} // common_fota + +#endif // DB_UPGRADER_HH_ \ No newline at end of file diff --git a/src/pkg_upgrade/src/db_upgrader.cc b/src/pkg_upgrade/src/db_upgrader.cc new file mode 100644 index 0000000..a756310 --- /dev/null +++ b/src/pkg_upgrade/src/db_upgrader.cc @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "db_upgrader.hh" + +#include + +#include + +#include "common_type.hh" +#include "logging.hh" + +namespace { + +constexpr char kDbPath[] = "/opt/dbspace/.pkgmgr_parser.db"; +constexpr char kSetRwPkgQuery[] = R"( +UPDATE package_info + SET package_preload='false', package_system='false', package_update='false' + WHERE package=? +)"; + +} // namespace + +namespace common_fota { + +using tizen_base::Database; +using tizen_base::DbException; + +DbUpgrader::DbUpgrader(const PkgContext& context, PkgOperation pkg_op) + : PkgUpgrader(context, pkg_op), pkgid_(context.GetId()) { +} + +bool DbUpgrader::Upgrade() { + if (GetLocation() == PkgLocation::RW) { + if (!SetRwPkg(pkgid_)) { + LOG(ERROR) << "Failed to update pkg " << pkgid_; + return false; + } + LOG(INFO) << "Preloaded files of " << pkgid_ << " has been removed. " + << "This package will be non-preload RW package"; + } + return true; +} + +bool DbUpgrader::SetRwPkg(const std::string& pkgid) { + try { + Database database(kDbPath, SQLITE_OPEN_READWRITE); + auto q = Database::Sql(kSetRwPkgQuery).Bind(pkgid); + auto guard = database.CreateTransactionGuard(); + auto r = database.Exec(q); + if (!r) { + LOG(ERROR) << "Update db failed: " << static_cast(r); + return false; + } + guard.Commit(); + } catch (DbException& e) { + LOG(ERROR) << "Exception during db operation: " << e.msg(); + return false; + } + + return true; +} + +} // namespace common_fota diff --git a/src/pkg_upgrade/src/pkg_finder.cc b/src/pkg_upgrade/src/pkg_finder.cc index e539317..fbf95de 100644 --- a/src/pkg_upgrade/src/pkg_finder.cc +++ b/src/pkg_upgrade/src/pkg_finder.cc @@ -132,8 +132,13 @@ int PkgFinder::PkgidListCb(const pkgmgrinfo_pkginfo_h handle, void* user_data) { if (pkgmgrinfo_pkginfo_get_type(handle, &type) != PMINFO_R_OK) return 0; + bool update = false; + if (pkgmgrinfo_pkginfo_is_update(handle, &update) != PMINFO_R_OK) + return 0; + PkgFinder* finder = static_cast(user_data); - finder->old_pkgs_.emplace_back(pkgid, version, type, finder->read_only_); + finder->old_pkgs_.emplace_back(pkgid, version, type, finder->read_only_, + update); return 0; } @@ -338,9 +343,9 @@ void PkgFinder::AddRwPkgInfoFromFile(const char* info_str) { }); if (removable == "false") - new_pkgs_.emplace_back(pkgid, version, type, false, false); + new_pkgs_.emplace_back(pkgid, version, type, false, false, false); else - new_pkgs_.emplace_back(pkgid, version, type, false, true); + new_pkgs_.emplace_back(pkgid, version, type, false, false, true); } string PkgFinder::GetToken(const char* pBuf, const char* pKey) { diff --git a/src/pkg_upgrade/src/pkg_upgrader_factory.cc b/src/pkg_upgrade/src/pkg_upgrader_factory.cc index 3e3499b..42f17cb 100644 --- a/src/pkg_upgrade/src/pkg_upgrader_factory.cc +++ b/src/pkg_upgrade/src/pkg_upgrader_factory.cc @@ -18,6 +18,7 @@ #include +#include "db_upgrader.hh" #include "logging.hh" #include "ro2rw_upgrader.hh" #include "ro_upgrader.hh" @@ -131,6 +132,9 @@ list> PkgUpgraderFactory::Merge( if (old_pkg.IsReadOnly()) { pkgs.emplace_back(std::make_unique(old_pkg, PkgOperation::UNINSTALL)); + } else if (old_pkg.IsUpdate()) { + pkgs.emplace_back(std::make_unique(old_pkg, + PkgOperation::COMPLEX)); } } } diff --git a/tests/mock/pkgmgr_info_mock.cc b/tests/mock/pkgmgr_info_mock.cc index f73cb5b..ca428c5 100644 --- a/tests/mock/pkgmgr_info_mock.cc +++ b/tests/mock/pkgmgr_info_mock.cc @@ -61,6 +61,12 @@ extern "C" int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, handle, version); } +extern "C" int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, + bool *update) { + return MOCK_HOOK_P2(PkgMgrInfoMock, pkgmgrinfo_pkginfo_is_update, + handle, update); +} + extern "C" int pkgmgrinfo_pkginfo_get_usr_pkginfo( const char* pkgid, uid_t uid, pkgmgrinfo_pkginfo_h* handle) { return MOCK_HOOK_P3( diff --git a/tests/mock/pkgmgr_info_mock.h b/tests/mock/pkgmgr_info_mock.h index bbc2a67..f008ae9 100644 --- a/tests/mock/pkgmgr_info_mock.h +++ b/tests/mock/pkgmgr_info_mock.h @@ -40,6 +40,7 @@ class PkgMgrInfoMock : public virtual ModuleMock { MOCK_METHOD2(pkgmgrinfo_pkginfo_get_type, int(pkgmgrinfo_pkginfo_h, char**)); MOCK_METHOD2(pkgmgrinfo_pkginfo_get_version, int(pkgmgrinfo_pkginfo_h, char**)); + MOCK_METHOD2(pkgmgrinfo_pkginfo_is_update, int(pkgmgrinfo_pkginfo_h, bool*)); MOCK_METHOD3(pkgmgrinfo_pkginfo_get_usr_pkginfo, int(const char*, uid_t, pkgmgrinfo_pkginfo_h*)); MOCK_METHOD1(pkgmgrinfo_pkginfo_destroy_pkginfo, int(pkgmgrinfo_pkginfo_h));