diff --git a/libs/linglong/src/linglong/builder/linglong_builder.cpp b/libs/linglong/src/linglong/builder/linglong_builder.cpp index 0f0ee34c1..1868c1523 100644 --- a/libs/linglong/src/linglong/builder/linglong_builder.cpp +++ b/libs/linglong/src/linglong/builder/linglong_builder.cpp @@ -155,11 +155,12 @@ utils::error::Result pullDependency(const package::Reference &ref, namespace detail { void mergeOutput(const std::vector &src, const std::filesystem::path &dest, - const std::vector &targets) + const std::vector &targets, + const std::vector &excludes) { for (const auto &dir : src) { LogD("merge {} to {}", dir, dest); - auto matcher = [&dir, &targets](const std::filesystem::path &path) { + auto matcher = [&dir, &targets, &excludes](const std::filesystem::path &path) { if (common::strings::starts_with(path.filename().string(), ".wh.")) { return false; } @@ -172,6 +173,11 @@ void mergeOutput(const std::vector &src, return false; } + for (const auto &exclude : excludes) { + if (common::strings::starts_with(path.string(), exclude)) { + return false; + } + } for (const auto &target : targets) { if (common::strings::starts_with(path.string(), target)) { return true; @@ -959,7 +965,10 @@ utils::error::Result Builder::buildStagePreCommit() noexcept src.push_back(runtimeOverlay->upperDirPath()); } } - detail::mergeOutput(src, buildOutput, { "bin/", "sbin/", "lib/" }); + detail::mergeOutput(src, + buildOutput, + { "bin/", "sbin/", "lib/" }, + { "lib/systemd", "share/systemd" }); return LINGLONG_OK; } diff --git a/libs/linglong/src/linglong/builder/linglong_builder.h b/libs/linglong/src/linglong/builder/linglong_builder.h index 47cc93a75..97da3328e 100644 --- a/libs/linglong/src/linglong/builder/linglong_builder.h +++ b/libs/linglong/src/linglong/builder/linglong_builder.h @@ -56,7 +56,8 @@ utils::error::Result cmdRemoveApp(repo::OSTreeRepo &repo, namespace detail { void mergeOutput(const std::vector &src, const std::filesystem::path &dest, - const std::vector &targets); + const std::vector &targets, + const std::vector &excludes); } class Builder diff --git a/libs/linglong/tests/ll-tests/src/linglong/builder/linglong_builder_test.cpp b/libs/linglong/tests/ll-tests/src/linglong/builder/linglong_builder_test.cpp index ed7e6c2d3..e70f0aa36 100644 --- a/libs/linglong/tests/ll-tests/src/linglong/builder/linglong_builder_test.cpp +++ b/libs/linglong/tests/ll-tests/src/linglong/builder/linglong_builder_test.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later #include @@ -111,10 +111,12 @@ TEST(LinglongBuilder, mergeOutput) const auto &srcPath1 = srcDir1.path(); std::filesystem::create_directories(srcPath1 / "bin"); std::filesystem::create_directories(srcPath1 / "lib"); + std::filesystem::create_directories(srcPath1 / "lib/systemd"); std::filesystem::create_directories(srcPath1 / "share"); std::ofstream(srcPath1 / "bin/tool1"); std::ofstream(srcPath1 / "lib/libfoo.so"); + std::ofstream(srcPath1 / "lib/systemd/dbus.service"); std::ofstream(srcPath1 / "share/data1"); std::ofstream(srcPath1 / ".wh.somefile"); @@ -130,7 +132,10 @@ TEST(LinglongBuilder, mergeOutput) // Define merge targets std::vector targets = { "bin/", "share/data1" }; - linglong::builder::detail::mergeOutput({ srcPath1, srcPath2 }, destDir.path(), targets); + linglong::builder::detail::mergeOutput({ srcPath1, srcPath2 }, + destDir.path(), + targets, + { "lib/systemd" }); const auto &destPath = destDir.path(); // Check files are merged @@ -143,6 +148,7 @@ TEST(LinglongBuilder, mergeOutput) EXPECT_FALSE(std::filesystem::exists(destPath / "lib/libbar.so")); EXPECT_FALSE(std::filesystem::exists(destPath / "share/data2")); EXPECT_FALSE(std::filesystem::exists(destPath / ".wh.somefile")); + EXPECT_FALSE(std::filesystem::exists(destPath / "lib/systemd/dbus.service")); } TEST(LinglongBuilder, UabExportFilename)