Skip to content

Commit 371c4bf

Browse files
committed
fix: exclude systemd files from merge output
1. Modified mergeOutput function to accept an 'excludes' parameter for filtering unwanted directories during file merging 2. Added logic to skip systemd-related files (lib/systemd, share/ systemd) during build stage 3. This prevents unnecessary systemd service files from being included in the final package output 4. Updated test to verify the exclusion mechanism works correctly Log: Systemd service files are no longer included in application packages by default Influence: 1. Test package building to ensure systemd files are excluded from output 2. Verify that other critical directories (bin/, lib/, sbin/) are still properly merged 3. Test with various source directory structures to ensure exclusion logic handles edge cases 4. Verify that existing packages still build correctly after this change 5. Check that .wh.* files continue to be excluded as expected fix: 从合并输出中排除 systemd 文件 1. 修改 mergeOutput 函数,添加 'excludes' 参数用于在文件合并时过滤不需要 的目录 2. 在构建阶段添加逻辑跳过 systemd 相关文件(lib/systemd, share/systemd) 3. 这防止不必要的 systemd 服务文件被包含在最终软件包输出中 4. 更新测试以验证排除机制正常工作 Log: Systemd 服务文件默认不再包含在应用程序包中 Influence: 1. 测试软件包构建,确保 systemd 文件被正确排除 2. 验证其他关键目录(bin/, lib/, sbin/)仍然正确合并 3. 使用不同的源目录结构测试,确保排除逻辑能处理边界情况 4. 验证现有软件包在此更改后仍然能正确构建 5. 检查 .wh.* 文件是否按预期继续被排除
1 parent 02e61e4 commit 371c4bf

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

libs/linglong/src/linglong/builder/linglong_builder.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ utils::error::Result<void> pullDependency(const package::Reference &ref,
155155
namespace detail {
156156
void mergeOutput(const std::vector<std::filesystem::path> &src,
157157
const std::filesystem::path &dest,
158-
const std::vector<std::string> &targets)
158+
const std::vector<std::string> &targets,
159+
const std::vector<std::string> &excludes)
159160
{
160161
for (const auto &dir : src) {
161162
LogD("merge {} to {}", dir, dest);
162-
auto matcher = [&dir, &targets](const std::filesystem::path &path) {
163+
auto matcher = [&dir, &targets, &excludes](const std::filesystem::path &path) {
163164
if (common::strings::starts_with(path.filename().string(), ".wh.")) {
164165
return false;
165166
}
@@ -172,6 +173,11 @@ void mergeOutput(const std::vector<std::filesystem::path> &src,
172173
return false;
173174
}
174175

176+
for (const auto &exclude : excludes) {
177+
if (common::strings::starts_with(path.string(), exclude)) {
178+
return false;
179+
}
180+
}
175181
for (const auto &target : targets) {
176182
if (common::strings::starts_with(path.string(), target)) {
177183
return true;
@@ -959,7 +965,10 @@ utils::error::Result<void> Builder::buildStagePreCommit() noexcept
959965
src.push_back(runtimeOverlay->upperDirPath());
960966
}
961967
}
962-
detail::mergeOutput(src, buildOutput, { "bin/", "sbin/", "lib/" });
968+
detail::mergeOutput(src,
969+
buildOutput,
970+
{ "bin/", "sbin/", "lib/" },
971+
{ "lib/systemd", "share/systemd" });
963972

964973
return LINGLONG_OK;
965974
}

libs/linglong/src/linglong/builder/linglong_builder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ utils::error::Result<void> cmdRemoveApp(repo::OSTreeRepo &repo,
5656
namespace detail {
5757
void mergeOutput(const std::vector<std::filesystem::path> &src,
5858
const std::filesystem::path &dest,
59-
const std::vector<std::string> &targets);
59+
const std::vector<std::string> &targets,
60+
const std::vector<std::string> &excludes);
6061
}
6162

6263
class Builder

libs/linglong/tests/ll-tests/src/linglong/builder/linglong_builder_test.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ TEST(LinglongBuilder, mergeOutput)
111111
const auto &srcPath1 = srcDir1.path();
112112
std::filesystem::create_directories(srcPath1 / "bin");
113113
std::filesystem::create_directories(srcPath1 / "lib");
114+
std::filesystem::create_directories(srcPath1 / "lib/systemd");
114115
std::filesystem::create_directories(srcPath1 / "share");
115116

116117
std::ofstream(srcPath1 / "bin/tool1");
117118
std::ofstream(srcPath1 / "lib/libfoo.so");
119+
std::ofstream(srcPath1 / "lib/systemd/dbus.service");
118120
std::ofstream(srcPath1 / "share/data1");
119121
std::ofstream(srcPath1 / ".wh.somefile");
120122

@@ -130,7 +132,10 @@ TEST(LinglongBuilder, mergeOutput)
130132
// Define merge targets
131133
std::vector<std::string> targets = { "bin/", "share/data1" };
132134

133-
linglong::builder::detail::mergeOutput({ srcPath1, srcPath2 }, destDir.path(), targets);
135+
linglong::builder::detail::mergeOutput({ srcPath1, srcPath2 },
136+
destDir.path(),
137+
targets,
138+
{ "lib/systemd" });
134139

135140
const auto &destPath = destDir.path();
136141
// Check files are merged
@@ -143,6 +148,7 @@ TEST(LinglongBuilder, mergeOutput)
143148
EXPECT_FALSE(std::filesystem::exists(destPath / "lib/libbar.so"));
144149
EXPECT_FALSE(std::filesystem::exists(destPath / "share/data2"));
145150
EXPECT_FALSE(std::filesystem::exists(destPath / ".wh.somefile"));
151+
EXPECT_FALSE(std::filesystem::exists(destPath / "lib/systemd/dbus.service"));
146152
}
147153

148154
TEST(LinglongBuilder, UabExportFilename)

0 commit comments

Comments
 (0)