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)
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")
BuildRequires: pkgconfig(storage)
BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(gmock)
+BuildRequires: tizen-database-devel
BuildRequires: pkgmgr-info-parser-devel
BuildRequires: pkgmgr-info-parser
BuildRequires: fdupes
APPLY_PKG_CONFIG(${TARGET_PKG_UPGRADE} PUBLIC
PKGMGR_INFO_DEPS
PKGMGR_PARSER_DEPS
+ TIZEN_DATABASE_DEPS
TZPLATFORM_DEPS
SMACK_DEPS
DLOG_DEPS
# Install
INSTALL(TARGETS ${TARGET_PKG_UPGRADE} DESTINATION bin)
-
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;
}
return PkgLocation::RW;
}
bool IsReadOnly() const { return read_only_; }
+ bool IsUpdate() const { return update_; }
bool IsRemovable() const { return removable_; }
private:
std::string version_;
std::string type_;
bool read_only_;
+ bool update_; // update means ReadonlyUpdated pkg
bool removable_;
};
--- /dev/null
+/*
+ * 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 <memory>
+
+#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
--- /dev/null
+/*
+ * 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 <sqlite3.h>
+
+#include <tizen-database/database.hpp>
+
+#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<int>(r);
+ return false;
+ }
+ guard.Commit();
+ } catch (DbException& e) {
+ LOG(ERROR) << "Exception during db operation: " << e.msg();
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace common_fota
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<PkgFinder*>(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;
}
});
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) {
#include <memory>
+#include "db_upgrader.hh"
#include "logging.hh"
#include "ro2rw_upgrader.hh"
#include "ro_upgrader.hh"
if (old_pkg.IsReadOnly()) {
pkgs.emplace_back(std::make_unique<SimpleUpgrader>(old_pkg,
PkgOperation::UNINSTALL));
+ } else if (old_pkg.IsUpdate()) {
+ pkgs.emplace_back(std::make_unique<DbUpgrader>(old_pkg,
+ PkgOperation::COMPLEX));
}
}
}
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(
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));