Skip to content
Merged
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
18 changes: 13 additions & 5 deletions libs/linglong/src/linglong/package_manager/package_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#include "linglong/package/reference.h"
#include "linglong/package/uab_file.h"
#include "linglong/package_manager/package_task.h"
#include "linglong/repo/config.h"

Check warning on line 23 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/repo/config.h" not found.
#include "linglong/repo/ostree_repo.h"

Check warning on line 24 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/repo/ostree_repo.h" not found.
#include "linglong/runtime/run_context.h"

Check warning on line 25 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/runtime/run_context.h" not found.
#include "linglong/utils/bash_quote.h"

Check warning on line 26 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/bash_quote.h" not found.
#include "linglong/utils/command/env.h"

Check warning on line 27 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/command/env.h" not found.
#include "linglong/utils/error/error.h"

Check warning on line 28 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/error/error.h" not found.
#include "linglong/utils/finally/finally.h"

Check warning on line 29 in libs/linglong/src/linglong/package_manager/package_manager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/finally/finally.h" not found.
#include "linglong/utils/hooks.h"
#include "linglong/utils/packageinfo_handler.h"
#include "linglong/utils/serialize/json.h"
Expand Down Expand Up @@ -2402,15 +2403,22 @@
if (!currentArch) {
return LINGLONG_ERR(currentArch);
}
const auto ldGenerateCmd = "/sbin/ldconfig -X -C " + appCacheDest + "/ld.so.cache";
auto ldGenerateCmd =
std::vector<std::string>{ "/sbin/ldconfig", "-X", "-C", appCacheDest + "/ld.so.cache" };
#ifdef LINGLONG_FONT_CACHE_GENERATOR
// Usage: font-cache-generator [cacheRoot] [id]
const std::string fontGenerateCmd =
fontGenerator + " " + appCacheDest + " " + ref.id.toStdString();
process.args = std::vector<std::string>{ "bash", "-c", ldGenerateCmd + ";" + fontGenerateCmd };
const std::string fontGenerateCmd = utils::quoteBashArg(fontGenerator) + " "
+ utils::quoteBashArg(appCacheDest) + " " + utils::quoteBashArg(ref.id.toStdString());
auto ldGenerateCmdstr;
for (const auto &c : ldGenerateCmd) {
ldGenerateCmdstr.append(utils::quoteBashArg(c));
ldGenerateCmdstr.append(" ");
}
process.args =
std::vector<std::string>{ "bash", "-c", ldGenerateCmdstr + ";" + fontGenerateCmd };
#endif

process.args = std::vector<std::string>{ ldGenerateCmd };
process.args = std::move(ldGenerateCmd);

// Note: XDG_RUNTIME_DIR is not set in PM, the ll-box will finally fallback to /run/ll-box.
// But PM has no write permission in that place, so we should specific the root path.
Expand Down
18 changes: 2 additions & 16 deletions libs/linglong/src/linglong/runtime/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* SPDX-License-Identifier: LGPL-3.0-or-later
*/

#include "linglong/runtime/container.h"

Check warning on line 7 in libs/linglong/src/linglong/runtime/container.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/runtime/container.h" not found.

#include "configure.h"

Check warning on line 9 in libs/linglong/src/linglong/runtime/container.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "configure.h" not found.
#include "linglong/utils/bash_quote.h"

Check warning on line 10 in libs/linglong/src/linglong/runtime/container.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/bash_quote.h" not found.
#include "linglong/utils/finally/finally.h"
#include "ocppi/runtime/RunOption.hpp"
#include "ocppi/runtime/config/types/Generators.hpp"
Expand Down Expand Up @@ -207,23 +208,8 @@
// environment variables
ofs << "exec ";

// quote the argument to avoid the space in the argument and use single quote to avoid the
// shell to expand the argument
// example:
// arg: "let's go"
// quoteArg: "'let'\''s go'"
auto quoteArg = [](std::string arg) {
const std::string quotePrefix = "'\\";
for (auto it = arg.begin(); it != arg.end(); it++) {
if (*it == '\'') {
it = arg.insert(it, quotePrefix.cbegin(), quotePrefix.cend());
it = arg.insert(it + quotePrefix.size() + 1, 1, '\'');
}
}
return "'" + arg + "'";
};
for (auto arg : originalArgs) {
ofs << quoteArg(arg) << " ";
ofs << utils::quoteBashArg(arg) << " ";
}
}

Expand Down
28 changes: 28 additions & 0 deletions libs/utils/src/linglong/utils/bash_quote.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include <string>

namespace linglong::utils {

// quote the bash argument to avoid the space in the argument
// and use single quote to avoid the shell to expand the argument
// example:
// arg: "let's go"
// quoted arg: "'let'\''s go'"
static inline std::string quoteBashArg(std::string arg) noexcept
{
const std::string quotePrefix = "'\\";
for (auto it = arg.begin(); it != arg.end(); it++) {
if (*it == '\'') {
it = arg.insert(it, quotePrefix.cbegin(), quotePrefix.cend());
it = arg.insert(it + quotePrefix.size() + 1, 1, '\'');
}
}
return "'" + arg + "'";
}

} // namespace linglong::utils