diff --git a/apps/ll-package-manager/src/main.cpp b/apps/ll-package-manager/src/main.cpp index 26137f8a6..f50da7939 100644 --- a/apps/ll-package-manager/src/main.cpp +++ b/apps/ll-package-manager/src/main.cpp @@ -11,7 +11,6 @@ #include "linglong/repo/ostree_repo.h" #include "linglong/utils/configure.h" #include "linglong/utils/dbus/register.h" -#include "linglong/utils/file.h" #include "linglong/utils/global/initialize.h" #include "ocppi/cli/CLI.hpp" #include "ocppi/cli/crun/Crun.hpp" @@ -51,23 +50,9 @@ void withDBusDaemon(ocppi::cli::CLI &cli) } auto *ostreeRepo = new linglong::repo::OSTreeRepo(repoRoot, *config, *clientFactory); ostreeRepo->setParent(QCoreApplication::instance()); - { - auto exportVersion = repoRoot.absoluteFilePath("entries/.version").toStdString(); - auto data = linglong::utils::readFile(exportVersion); - if (data && data == LINGLONG_EXPORT_VERSION) { - qDebug() << exportVersion.c_str() << data->c_str(); - qDebug() << "skip export entry, already exported"; - } else { - auto ret = ostreeRepo->exportAllEntries(); - if (!ret.has_value()) { - qCritical() << "failed to export entries:" << ret.error(); - } else { - ret = linglong::utils::writeFile(exportVersion, LINGLONG_EXPORT_VERSION); - if (!ret.has_value()) { - qCritical() << "failed to write export version:" << ret.error(); - } - } - } + auto result = ostreeRepo->fixExportAllEntries(); + if (!result.has_value()) { + qCritical() << result.error().message(); } auto *containerBuilder = new linglong::runtime::ContainerBuilder(cli); @@ -78,7 +63,7 @@ void withDBusDaemon(ocppi::cli::CLI &cli) *containerBuilder, QCoreApplication::instance()); new linglong::adaptors::package_manger::PackageManager1(packageManager); - auto result = registerDBusObject(conn, "/org/deepin/linglong/PackageManager1", packageManager); + result = registerDBusObject(conn, "/org/deepin/linglong/PackageManager1", packageManager); if (!result.has_value()) { qCritical().noquote() << "Launching failed:" << Qt::endl << result.error().message(); QCoreApplication::exit(-1); @@ -126,6 +111,10 @@ void withoutDBusDaemon(ocppi::cli::CLI &cli) auto *ostreeRepo = new linglong::repo::OSTreeRepo(repoRoot, *config, *clientFactory); ostreeRepo->setParent(QCoreApplication::instance()); + auto result = ostreeRepo->fixExportAllEntries(); + if (!result.has_value()) { + qCritical() << result.error().message(); + } auto *containerBuilder = new linglong::runtime::ContainerBuilder(cli); containerBuilder->setParent(QCoreApplication::instance()); diff --git a/libs/linglong/src/linglong/repo/ostree_repo.cpp b/libs/linglong/src/linglong/repo/ostree_repo.cpp index 9ffea0ddb..11ee13a42 100644 --- a/libs/linglong/src/linglong/repo/ostree_repo.cpp +++ b/libs/linglong/src/linglong/repo/ostree_repo.cpp @@ -18,6 +18,7 @@ #include "linglong/repo/config.h" #include "linglong/utils/command/env.h" #include "linglong/utils/error/error.h" +#include "linglong/utils/file.h" #include "linglong/utils/finally/finally.h" #include "linglong/utils/gkeyfile_wrapper.h" #include "linglong/utils/packageinfo_handler.h" @@ -1640,8 +1641,37 @@ utils::error::Result OSTreeRepo::exportDir(const std::string &appID, return LINGLONG_ERR("remove file failed", ec); } } - auto ret = IniLikeFileRewrite(QFileInfo(source_path.c_str()), appID.c_str()); - if (!ret) { } + + { + auto info = QFileInfo(target_path.c_str()); + if ((info.path().contains("share/applications") && info.suffix() == "desktop") + || (info.path().contains("share/dbus-1") && info.suffix() == "service") + || (info.path().contains("share/systemd/user") && info.suffix() == "service") + || (info.path().contains("share/applications/context-menus"))) { + // We should not modify the files of the checked application directly, but + // should copy them to root entries directory and then modify. + std::filesystem::copy(source_path, target_path, ec); + if (ec) { + return LINGLONG_ERR("copy file failed: " + target_path.string(), ec); + } + + exists = std::filesystem::exists(target_path, ec); + if (ec) { + return LINGLONG_ERR("check file exists", ec); + } + + if (!exists) { + qWarning() << "failed to copy file: " << source_path.c_str(); + continue; + } + + auto ret = IniLikeFileRewrite(QFileInfo(target_path.c_str()), appID.c_str()); + if (ret) { + continue; + } + } + } + std::filesystem::create_symlink(source_path, target_path, ec); if (ec) { return LINGLONG_ERR("create symlink failed: " + target_path.string(), ec); @@ -1735,6 +1765,30 @@ OSTreeRepo::exportEntries(const std::filesystem::path &rootEntriesDir, return LINGLONG_OK; } +utils::error::Result OSTreeRepo::fixExportAllEntries() noexcept +{ + auto exportVersion = repoDir.absoluteFilePath("entries/.version").toStdString(); + auto data = linglong::utils::readFile(exportVersion); + if (data && data == LINGLONG_EXPORT_VERSION) { + qDebug() << exportVersion.c_str() << data->c_str(); + qDebug() << "skip export entry, already exported"; + } else { + auto ret = exportAllEntries(); + if (!ret.has_value()) { + qCritical() << "failed to export entries:" << ret.error(); + return ret; + } else { + ret = linglong::utils::writeFile(exportVersion, LINGLONG_EXPORT_VERSION); + if (!ret.has_value()) { + qCritical() << "failed to write export version:" << ret.error(); + return ret; + } + } + } + + return LINGLONG_OK; +} + utils::error::Result OSTreeRepo::exportAllEntries() noexcept { LINGLONG_TRACE("export all entries"); diff --git a/libs/linglong/src/linglong/repo/ostree_repo.h b/libs/linglong/src/linglong/repo/ostree_repo.h index 392198891..a7a40bafe 100644 --- a/libs/linglong/src/linglong/repo/ostree_repo.h +++ b/libs/linglong/src/linglong/repo/ostree_repo.h @@ -90,8 +90,6 @@ class OSTreeRepo : public QObject utils::error::Result prune(); void removeDanglingXDGIntergation() noexcept; - // exportEntries will clear the entries/share and export all applications to the entries/share - utils::error::Result exportAllEntries() noexcept; // exportReference should be called when LayerDir of ref is existed in local repo void exportReference(const package::Reference &ref) noexcept; // unexportReference should be called when LayerDir of ref is existed in local repo @@ -121,6 +119,7 @@ class OSTreeRepo : public QObject getLayerItem(const package::Reference &ref, std::string module = "binary", const std::optional &subRef = std::nullopt) const noexcept; + utils::error::Result fixExportAllEntries() noexcept; private: api::types::v1::RepoConfig cfg; @@ -164,6 +163,8 @@ class OSTreeRepo : public QObject const std::filesystem::path &source, const std::filesystem::path &destination, const int &max_depth); + // exportEntries will clear the entries/share and export all applications to the entries/share + utils::error::Result exportAllEntries() noexcept; }; } // namespace linglong::repo