Skip to content

Commit da55165

Browse files
dengbo11black-desk
authored andcommitted
fix: error to export applications entries directory
1. we must fix export entries when in no dbus mode; 2. we must copy application entries directorys to the root entries directorys before rewrite file;
1 parent 8e44f4d commit da55165

File tree

3 files changed

+67
-23
lines changed

3 files changed

+67
-23
lines changed

apps/ll-package-manager/src/main.cpp

+8-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "linglong/repo/ostree_repo.h"
1212
#include "linglong/utils/configure.h"
1313
#include "linglong/utils/dbus/register.h"
14-
#include "linglong/utils/file.h"
1514
#include "linglong/utils/global/initialize.h"
1615
#include "ocppi/cli/CLI.hpp"
1716
#include "ocppi/cli/crun/Crun.hpp"
@@ -51,23 +50,9 @@ void withDBusDaemon(ocppi::cli::CLI &cli)
5150
}
5251
auto *ostreeRepo = new linglong::repo::OSTreeRepo(repoRoot, *config, *clientFactory);
5352
ostreeRepo->setParent(QCoreApplication::instance());
54-
{
55-
auto exportVersion = repoRoot.absoluteFilePath("entries/.version").toStdString();
56-
auto data = linglong::utils::readFile(exportVersion);
57-
if (data && data == LINGLONG_EXPORT_VERSION) {
58-
qDebug() << exportVersion.c_str() << data->c_str();
59-
qDebug() << "skip export entry, already exported";
60-
} else {
61-
auto ret = ostreeRepo->exportAllEntries();
62-
if (!ret.has_value()) {
63-
qCritical() << "failed to export entries:" << ret.error();
64-
} else {
65-
ret = linglong::utils::writeFile(exportVersion, LINGLONG_EXPORT_VERSION);
66-
if (!ret.has_value()) {
67-
qCritical() << "failed to write export version:" << ret.error();
68-
}
69-
}
70-
}
53+
auto result = ostreeRepo->fixExportAllEntries();
54+
if (!result.has_value()) {
55+
qCritical() << result.error().message();
7156
}
7257

7358
auto *containerBuilder = new linglong::runtime::ContainerBuilder(cli);
@@ -78,7 +63,7 @@ void withDBusDaemon(ocppi::cli::CLI &cli)
7863
*containerBuilder,
7964
QCoreApplication::instance());
8065
new linglong::adaptors::package_manger::PackageManager1(packageManager);
81-
auto result = registerDBusObject(conn, "/org/deepin/linglong/PackageManager1", packageManager);
66+
result = registerDBusObject(conn, "/org/deepin/linglong/PackageManager1", packageManager);
8267
if (!result.has_value()) {
8368
qCritical().noquote() << "Launching failed:" << Qt::endl << result.error().message();
8469
QCoreApplication::exit(-1);
@@ -126,6 +111,10 @@ void withoutDBusDaemon(ocppi::cli::CLI &cli)
126111

127112
auto *ostreeRepo = new linglong::repo::OSTreeRepo(repoRoot, *config, *clientFactory);
128113
ostreeRepo->setParent(QCoreApplication::instance());
114+
auto result = ostreeRepo->fixExportAllEntries();
115+
if (!result.has_value()) {
116+
qCritical() << result.error().message();
117+
}
129118

130119
auto *containerBuilder = new linglong::runtime::ContainerBuilder(cli);
131120
containerBuilder->setParent(QCoreApplication::instance());

libs/linglong/src/linglong/repo/ostree_repo.cpp

+56-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "linglong/repo/config.h"
1919
#include "linglong/utils/command/env.h"
2020
#include "linglong/utils/error/error.h"
21+
#include "linglong/utils/file.h"
2122
#include "linglong/utils/finally/finally.h"
2223
#include "linglong/utils/gkeyfile_wrapper.h"
2324
#include "linglong/utils/packageinfo_handler.h"
@@ -1640,8 +1641,37 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
16401641
return LINGLONG_ERR("remove file failed", ec);
16411642
}
16421643
}
1643-
auto ret = IniLikeFileRewrite(QFileInfo(source_path.c_str()), appID.c_str());
1644-
if (!ret) { }
1644+
1645+
{
1646+
auto info = QFileInfo(target_path.c_str());
1647+
if ((info.path().contains("share/applications") && info.suffix() == "desktop")
1648+
|| (info.path().contains("share/dbus-1") && info.suffix() == "service")
1649+
|| (info.path().contains("share/systemd/user") && info.suffix() == "service")
1650+
|| (info.path().contains("share/applications/context-menus"))) {
1651+
// We should not modify the files of the checked application directly, but
1652+
// should copy them to root entries directory and then modify.
1653+
std::filesystem::copy(source_path, target_path, ec);
1654+
if (ec) {
1655+
return LINGLONG_ERR("copy file failed: " + target_path.string(), ec);
1656+
}
1657+
1658+
exists = std::filesystem::exists(target_path, ec);
1659+
if (ec) {
1660+
return LINGLONG_ERR("check file exists", ec);
1661+
}
1662+
1663+
if (!exists) {
1664+
qWarning() << "failed to copy file: " << source_path.c_str();
1665+
continue;
1666+
}
1667+
1668+
auto ret = IniLikeFileRewrite(QFileInfo(target_path.c_str()), appID.c_str());
1669+
if (ret) {
1670+
continue;
1671+
}
1672+
}
1673+
}
1674+
16451675
std::filesystem::create_symlink(source_path, target_path, ec);
16461676
if (ec) {
16471677
return LINGLONG_ERR("create symlink failed: " + target_path.string(), ec);
@@ -1735,6 +1765,30 @@ OSTreeRepo::exportEntries(const std::filesystem::path &rootEntriesDir,
17351765
return LINGLONG_OK;
17361766
}
17371767

1768+
utils::error::Result<void> OSTreeRepo::fixExportAllEntries() noexcept
1769+
{
1770+
auto exportVersion = repoDir.absoluteFilePath("entries/.version").toStdString();
1771+
auto data = linglong::utils::readFile(exportVersion);
1772+
if (data && data == LINGLONG_EXPORT_VERSION) {
1773+
qDebug() << exportVersion.c_str() << data->c_str();
1774+
qDebug() << "skip export entry, already exported";
1775+
} else {
1776+
auto ret = exportAllEntries();
1777+
if (!ret.has_value()) {
1778+
qCritical() << "failed to export entries:" << ret.error();
1779+
return ret;
1780+
} else {
1781+
ret = linglong::utils::writeFile(exportVersion, LINGLONG_EXPORT_VERSION);
1782+
if (!ret.has_value()) {
1783+
qCritical() << "failed to write export version:" << ret.error();
1784+
return ret;
1785+
}
1786+
}
1787+
}
1788+
1789+
return LINGLONG_OK;
1790+
}
1791+
17381792
utils::error::Result<void> OSTreeRepo::exportAllEntries() noexcept
17391793
{
17401794
LINGLONG_TRACE("export all entries");

libs/linglong/src/linglong/repo/ostree_repo.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ class OSTreeRepo : public QObject
9090
utils::error::Result<void> prune();
9191

9292
void removeDanglingXDGIntergation() noexcept;
93-
// exportEntries will clear the entries/share and export all applications to the entries/share
94-
utils::error::Result<void> exportAllEntries() noexcept;
9593
// exportReference should be called when LayerDir of ref is existed in local repo
9694
void exportReference(const package::Reference &ref) noexcept;
9795
// unexportReference should be called when LayerDir of ref is existed in local repo
@@ -121,6 +119,7 @@ class OSTreeRepo : public QObject
121119
getLayerItem(const package::Reference &ref,
122120
std::string module = "binary",
123121
const std::optional<std::string> &subRef = std::nullopt) const noexcept;
122+
utils::error::Result<void> fixExportAllEntries() noexcept;
124123

125124
private:
126125
api::types::v1::RepoConfig cfg;
@@ -164,6 +163,8 @@ class OSTreeRepo : public QObject
164163
const std::filesystem::path &source,
165164
const std::filesystem::path &destination,
166165
const int &max_depth);
166+
// exportEntries will clear the entries/share and export all applications to the entries/share
167+
utils::error::Result<void> exportAllEntries() noexcept;
167168
};
168169

169170
} // namespace linglong::repo

0 commit comments

Comments
 (0)