Compare commits

...

4 Commits

Author SHA1 Message Date
dengbo 76f93d96f9 fix: Refactors logging system initialization to use explicit backend
build / ubuntu_24.04 (push) Has been cancelled Details
build / ubuntu_22.04 (push) Has been cancelled Details
coverage / codecov (push) Has been cancelled Details
Replaces command-based initialization of the logging system with
an explicit backend parameter, simplifying configuration logic
and improving maintainability.

Removes redundant code that inferred the log backend from
command names. Updates all affected components to pass the
appropriate backend directly when initializing the log system.
2025-11-14 14:56:49 +08:00
dengbo c94a0dc829 refactor: Simplifies icon packaging logic in UABPackager
Refactors the icon packaging process by removing the intermediate
step of creating an "icon.a" archive and directly passing the
icon value to the `addNewSection` method. Improves code
clarity and reduces unnecessary operations.
2025-11-14 14:56:49 +08:00
dengbo 9b302b55dd fix: the application was abnormally removed due to an error in executing hooks
1. Hook scripts should be executed before exporting and generating caches; otherwise, execution failures may result in the application being removed.
2. Enhances logging for better visibility into hook execution
failures and aligns hook handling across installation, upgrade,
and dependency management workflows.
2025-11-14 14:56:49 +08:00
dengbo cdc9420a48 fix: There will be multiple versions of the application when an error occurs during the upgrade process
1. Adds rollback mechanism for package installation when install new ref in update.
2. Remove OSTreeRepo redundant transaction.
2025-11-14 14:56:49 +08:00
9 changed files with 72 additions and 66 deletions

View File

@ -746,7 +746,7 @@ int main(int argc, char **argv)
Q_INIT_RESOURCE(builder_releases);
// 初始化应用builder在非tty环境也输出日志
linglong::utils::global::applicationInitialize(true);
linglong::utils::global::initLinyapsLogSystem(argv[0]);
linglong::utils::global::initLinyapsLogSystem(linglong::utils::log::LogBackend::Console);
CLI::App commandParser{ _("linyaps builder CLI \n"
"A CLI program to build linyaps application\n") };

View File

@ -930,7 +930,7 @@ int main(int argc, char **argv)
QCoreApplication app(argc, argv);
// application initialize
applicationInitialize();
initLinyapsLogSystem(argv[0]);
initLinyapsLogSystem(linglong::utils::log::LogBackend::Journal);
// invoke method
auto ret = QMetaObject::invokeMethod(

View File

@ -159,7 +159,7 @@ auto main(int argc, char *argv[]) -> int
QCoreApplication app(argc, argv);
applicationInitialize();
initLinyapsLogSystem(argv[0]);
initLinyapsLogSystem(linglong::utils::log::LogBackend::Journal);
auto ociRuntimeCLI = qgetenv("LINGLONG_OCI_RUNTIME");
if (ociRuntimeCLI.isEmpty()) {

View File

@ -280,14 +280,8 @@ utils::error::Result<void> UABPackager::packIcon() noexcept
{
LINGLONG_TRACE("add icon to uab")
auto iconAchieve = this->uab.parentDir().absoluteFilePath("icon.a");
if (auto ret = utils::command::Cmd("ar").exec({ "q", iconAchieve, icon->absoluteFilePath() });
!ret) {
return LINGLONG_ERR(ret);
}
QByteArray iconSection{ "linglong.icon" };
if (auto ret = this->uab.addNewSection(iconSection, QFileInfo{ iconAchieve }); !ret) {
if (auto ret = this->uab.addNewSection(iconSection, icon.value()); !ret) {
return LINGLONG_ERR(ret);
}

View File

@ -724,13 +724,19 @@ QVariantMap PackageManager::installFromLayer(const QDBusUnixFileDescriptor &fd,
return;
}
if (!localRef) {
auto newRef = package::Reference::fromPackageInfo(*info);
if (!newRef) {
taskRef.reportError(std::move(newRef).error());
return;
}
auto newRef = package::Reference::fromPackageInfo(*info);
if (!newRef) {
taskRef.reportError(std::move(newRef).error());
return;
}
auto ret = executePostInstallHooks(*newRef);
if (!ret) {
taskRef.reportError(std::move(ret).error());
return;
}
if (!localRef) {
auto generateCacheRet = this->tryGenerateCache(*newRef);
if (!generateCacheRet) {
taskRef.reportError(std::move(generateCacheRet).error());
@ -746,30 +752,18 @@ QVariantMap PackageManager::installFromLayer(const QDBusUnixFileDescriptor &fd,
return;
}
auto newRef = package::Reference::fromPackageInfo(*info);
if (!newRef) {
taskRef.reportError(std::move(newRef).error());
return;
}
auto generateCacheRet = this->tryGenerateCache(*newRef);
if (!generateCacheRet) {
taskRef.reportError(std::move(generateCacheRet).error());
return;
}
auto ret = removeAfterInstall(*localRef, *newRef, std::vector{ module });
ret = removeAfterInstall(*localRef, *newRef, std::vector{ module });
if (!ret) {
qCritical() << "failed to remove old reference" << localRef->toString()
<< "after install" << packageRef.toString() << ":"
<< ret.error().message();
}
ret = executePostInstallHooks(*newRef);
if (!ret) {
taskRef.reportError(std::move(ret).error());
return;
}
};
auto refSpec =
@ -1090,7 +1084,19 @@ QVariantMap PackageManager::installFromUAB(const QDBusUnixFileDescriptor &fd,
if (!ret) {
qCritical() << "rollback importLayerDir failed:" << ret.error().message();
}
ret = executePostUninstallHooks(layerRef);
if (!ret) {
LogE("failed to rollback execute uninstall hooks: {}", ret.error());
Q_ASSERT(false);
}
});
auto result = executePostInstallHooks(ref);
if (!result) {
taskRef.reportError(std::move(result).error());
return;
}
}
if (oldAppRef) {
@ -1116,12 +1122,6 @@ QVariantMap PackageManager::installFromUAB(const QDBusUnixFileDescriptor &fd,
}
}
auto ret = executePostInstallHooks(newAppRef);
if (!ret) {
taskRef.reportError(std::move(ret).error());
return;
}
transaction.commit();
taskRef.updateState(linglong::api::types::v1::State::Succeed, "install uab successfully");
};
@ -1436,6 +1436,7 @@ void PackageManager::Install(PackageTask &taskContext,
utils::error::ErrorCode::AppInstallModuleNotFound));
return;
}
InstallRef(taskContext,
newRef,
installModules->second,
@ -1450,8 +1451,20 @@ void PackageManager::Install(PackageTask &taskContext,
if (tmp.state() != linglong::api::types::v1::State::Succeed) {
LogE("failed to rollback install {}", newRef.toString());
}
auto ret = executePostUninstallHooks(newRef);
if (!ret) {
LogE("failed to rollback execute uninstall hooks: {}", ret.error());
}
});
auto ret = executePostInstallHooks(newRef);
if (!ret) {
taskContext.updateState(linglong::api::types::v1::State::Failed,
"Failed to execute postInstall hooks.\n" + ret.error().message());
return;
}
taskContext.updateSubState(linglong::api::types::v1::SubState::PostAction,
"processing after install");
@ -1490,13 +1503,6 @@ void PackageManager::Install(PackageTask &taskContext,
}
}
auto ret = executePostInstallHooks(newRef);
if (!ret) {
taskContext.updateState(linglong::api::types::v1::State::Failed,
"Failed to execute postInstall hooks.\n" + ret.error().message());
return;
}
transaction.commit();
taskContext.updateState(linglong::api::types::v1::State::Succeed,
"Install " + newRef.toString() + " (from repo: "
@ -1947,8 +1953,21 @@ void PackageManager::Update(PackageTask &taskContext,
if (tmp.state() != linglong::api::types::v1::State::Succeed) {
LogE("failed to rollback install {}", newRef.toString());
}
auto ret = executePostUninstallHooks(newRef);
if (!ret) {
LogE("failed to rollback execute uninstall hooks: {}", ret.error());
}
});
auto result = executePostInstallHooks(newRef);
if (!result) {
taskContext.updateState(linglong::api::types::v1::State::Failed,
"Failed to execute postInstall hooks.\n"
+ result.error().message());
return;
}
auto oldRefLayerItem = this->repo.getLayerItem(oldRef);
taskContext.updateState(
@ -1983,12 +2002,6 @@ void PackageManager::Update(PackageTask &taskContext,
return;
}
ret = executePostInstallHooks(newRef);
if (!ret) {
qCritical() << "failed to execute post install hooks" << ret.error().message();
return;
}
auto result = this->tryGenerateCache(newRef);
if (!result) {
taskContext.reportError(
@ -2142,14 +2155,14 @@ void PackageManager::pullDependency(PackageTask &taskContext,
transaction.addRollBack([this, runtimeRef = *runtime, module]() noexcept {
auto result = this->repo.remove(runtimeRef.reference, module);
if (!result) {
qCritical() << result.error();
Q_ASSERT(false);
LogE("failed to remove remote reference: {} : {}",
runtimeRef.reference.toString(),
result.error().message());
}
result = executePostUninstallHooks(runtimeRef.reference);
if (!result) {
qCritical() << result.error();
Q_ASSERT(false);
LogE("failed to rollback execute uninstall hooks: {}", result.error());
}
});
}
@ -2210,13 +2223,14 @@ void PackageManager::pullDependency(PackageTask &taskContext,
transaction.addRollBack([this, baseRef = *base, module]() noexcept {
auto result = this->repo.remove(baseRef.reference, module);
if (!result) {
qCritical() << result.error();
Q_ASSERT(false);
LogE("failed to remove remote reference: {} : {}",
baseRef.reference.toString(),
result.error().message());
}
result = executePostUninstallHooks(baseRef.reference);
if (!result) {
qCritical() << result.error();
LogE("failed to rollback execute uninstall hooks: {}", result.error());
Q_ASSERT(false);
}
});

View File

@ -100,6 +100,9 @@ public
// Nothing to do here, Permissions() will be rejected in org.deepin.linglong.PackageManager.conf
void Permissions() { }
utils::error::Result<void> executePostInstallHooks(const package::Reference &ref) noexcept;
utils::error::Result<void> executePostUninstallHooks(const package::Reference &ref) noexcept;
Q_SIGNALS:
void TaskAdded(QDBusObjectPath object_path);
void TaskRemoved(QDBusObjectPath object_path,
@ -156,8 +159,6 @@ private:
utils::error::Result<void> generateCache(const package::Reference &ref) noexcept;
utils::error::Result<void> tryGenerateCache(const package::Reference &ref) noexcept;
utils::error::Result<void> removeCache(const package::Reference &ref) noexcept;
utils::error::Result<void> executePostInstallHooks(const package::Reference &ref) noexcept;
utils::error::Result<void> executePostUninstallHooks(const package::Reference &ref) noexcept;
linglong::repo::OSTreeRepo &repo; // NOLINT
PackageTaskQueue tasks;

View File

@ -14,6 +14,7 @@ int main(int argc, char **argv)
{
qputenv("QT_FORCE_STDERR_LOGGING", QByteArray("1"));
linglong::utils::global::installMessageHandler();
linglong::utils::global::initLinyapsLogSystem(linglong::utils::log::LogBackend::Console);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -151,7 +151,7 @@ LogBackend parseLogBackend(const char *backends)
} // namespace
void initLinyapsLogSystem(const char *command)
void initLinyapsLogSystem(linglong::utils::log::LogBackend backend)
{
LogLevel logLevel = LogLevel::Info;
LogBackend logBackend = LogBackend::None;
@ -165,13 +165,7 @@ void initLinyapsLogSystem(const char *command)
if (logBackendEnv) {
logBackend = parseLogBackend(logBackendEnv);
} else {
if (command == std::string("ll-builder")) {
logBackend = LogBackend::Console;
} else if (command == std::string("ll-cli")) {
logBackend = LogBackend::Journal;
} else if (command == std::string("ll-package-manager")) {
logBackend = LogBackend::Journal;
}
logBackend = backend;
if (isatty(STDERR_FILENO)) {
logBackend = logBackend | LogBackend::Console;

View File

@ -6,6 +6,8 @@
#pragma once
#include "linglong/utils/log/log.h"
#include <QObject>
#include <atomic>
@ -16,7 +18,7 @@ void applicationInitialize(bool appForceStderrLogging = false);
void installMessageHandler();
bool linglongInstalled();
void cancelAllTask() noexcept;
void initLinyapsLogSystem(const char *command);
void initLinyapsLogSystem(linglong::utils::log::LogBackend backend);
class GlobalTaskControl : public QObject
{