Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libs/linglong/src/linglong/repo/ostree_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,9 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
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/systemd/user")
|| info.path().contains("lib/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 and then modify.
Expand Down Expand Up @@ -3232,7 +3234,9 @@ utils::error::Result<void> OSTreeRepo::IniLikeFileRewrite(const QFileInfo &info,

} else if (info.path().contains("share/dbus-1") && info.suffix() == "service") {
return dbusServiceRewrite(info.absoluteFilePath(), id);
} else if (info.path().contains("share/systemd/user") && info.suffix() == "service") {
} else if ((info.path().contains("share/systemd/user")
|| info.path().contains("lib/systemd/user"))
&& info.suffix() == "service") {
return systemdServiceRewrite(info.absoluteFilePath(), id);
} else if (info.path().contains("share/applications/context-menus")
&& info.suffix() == "conf") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gmock/gmock.h>
#include <gtest/gtest.h>

Check warning on line 6 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "../../common/tempdir.h"
#include "../mocks/ostree_repo_mock.h"

Check warning on line 9 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/api/types/v1/Generators.hpp" not found.
#include "configure.h"

Check warning on line 10 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/package/fuzzy_reference.h" not found.
#include "linglong/api/types/v1/Generators.hpp"

Check warning on line 11 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/package/layer_dir.h" not found.
#include "linglong/builder/builder_script.h"

Check warning on line 12 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/package/reference.h" not found.
#include "linglong/common/gkeyfile_wrapper.h"

Check warning on line 13 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/repo/ostree_repo.h" not found.
#include "linglong/package/fuzzy_reference.h"
#include "linglong/package/layer_dir.h"

Check warning on line 15 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <filesystem> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "linglong/package/reference.h"

Check warning on line 16 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <fstream> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "linglong/repo/ostree_repo.h"

Check warning on line 17 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <memory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "linglong/utils/cmd.h"

Check warning on line 18 in libs/linglong/tests/ll-tests/src/linglong/repo/ostree_repo_real_test.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <optional> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -353,6 +358,82 @@
fs::remove_all(tmp->path(), ec);
}

TEST_F(RealRepoTest, ExportSystemdServicesRewritesCommandsForBothLayouts)
{
using KeyFile = common::GKeyFileWrapper;
auto generator = builder::findBuilderScript("app-conf-generator");
ASSERT_TRUE(generator.has_value()) << generator.error().message();

// This wrapper only exposes exportDir; its callbacks remain unset.
MockOstreeRepo exporter(repoRoot, makeRepoConfig());
for (const auto *layout : { "lib", "share" }) {
SCOPED_TRACE(layout);
const auto id = std::string("com.example.service.") + layout;
const auto stage = repoRoot / (std::string("service-source-") + layout);
const auto relative = fs::path(layout) / "systemd/user";
const auto name = id + ".service";
const auto service = stage / "files" / relative / name;
const auto start = "/opt/apps/" + id + "/files/bin/main";
const auto post = "/opt/apps/" + id + "/files/bin/post";
fs::create_directories(service.parent_path());
std::ofstream(service) << "[Service]\nType=oneshot\nExecStart=" << start
<< "\nExecStartPost=" << post << '\n';

auto generated =
utils::Cmd("bash").exec({ "-e", generator->string(), id, (stage / "files").string() });
ASSERT_TRUE(generated.has_value()) << generated.error().message();
auto before = KeyFile::New(QString::fromStdString(service.string()));
ASSERT_TRUE(before.has_value()) << before.error().message();
auto generatedStart = before->getValue<QString>("ExecStart", KeyFile::SystemdService);
auto generatedPost = before->getValue<QString>("ExecStartPost", KeyFile::SystemdService);
ASSERT_TRUE(generatedStart.has_value());
ASSERT_TRUE(generatedPost.has_value());
ASSERT_EQ(*generatedStart,
QString::fromStdString("/usr/bin/ll-cli run " + id + " -- " + start));
ASSERT_EQ(*generatedPost, QString::fromStdString(post));

fs::create_directories(stage / "entries" / relative);
fs::copy_file(service, stage / "entries" / relative / name);
PackageInfoV2 info;
info.id = id;
info.version = "1.0.0";
info.kind = "app";
info.channel = "stable";
info.arch = { "x86_64" };
info.packageInfoV2Module = "binary";
std::ofstream(stage / "info.json") << nlohmann::json(info).dump();
auto imported = repo->importLayerDir(LayerDir(stage));
ASSERT_TRUE(imported.has_value()) << imported.error().message();
auto ref = Reference::fromPackageInfo(info);
ASSERT_TRUE(ref.has_value()) << ref.error().message();
auto layer = repo->getLayerDir(*ref, "binary");
ASSERT_TRUE(layer.has_value()) << layer.error().message();
const auto source = layer->path() / "entries" / relative;
ASSERT_GT(fs::hard_link_count(source / name), 1);

const auto destination = repoRoot / "entries";
const auto exportedPath = destination / "lib/systemd/user" / name;
const auto prefix = std::string(LINGLONG_CLIENT_PATH) + " run " + id + " -- ";
for (int pass = 0; pass < 2; ++pass) {
SCOPED_TRACE(pass);
auto exported = exporter.exportDir(id, source, destination, "lib/systemd/user", 10);
ASSERT_TRUE(exported.has_value()) << exported.error().message();
ASSERT_TRUE(fs::is_symlink(exportedPath));
auto after = KeyFile::New(QString::fromStdString(exportedPath.string()));
ASSERT_TRUE(after.has_value()) << after.error().message();
auto exportedStart = after->getValue<QString>("ExecStart", KeyFile::SystemdService);
auto exportedPost = after->getValue<QString>("ExecStartPost", KeyFile::SystemdService);
auto type = after->getValue<QString>("Type", KeyFile::SystemdService);
ASSERT_TRUE(exportedStart.has_value());
ASSERT_TRUE(exportedPost.has_value());
ASSERT_TRUE(type.has_value());
EXPECT_EQ(*exportedStart, QString::fromStdString(prefix + start));
EXPECT_EQ(*exportedPost, QString::fromStdString(prefix + post));
EXPECT_EQ(*type, "oneshot");
}
}
}

TEST_F(RealRepoTest, ListLocalByQuery)
{
auto all = repo->listLocalBy(repoCacheQuery{ .id = "com.example.app" });
Expand Down
Loading