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
10 changes: 7 additions & 3 deletions apps/ll-driver-detect/src/nvidia_driver_detector.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand Down Expand Up @@ -82,7 +82,9 @@ NVIDIADriverDetector::getPackageInfoFromRemoteRepo(const std::string &packageNam

LINGLONG_TRACE("Check if NVIDIA driver package exists in repository");

GraphicsDriverInfo driverInfo{ getDriverIdentify(), packageName };
GraphicsDriverInfo driverInfo;
driverInfo.identify = getDriverIdentify();
driverInfo.packageName = packageName;
// Execute ll-cli search command to check driver package existence
auto ret = linglong::utils::Cmd("ll-cli").exec({ "--json", "search", packageName });
if (!ret) {
Expand Down Expand Up @@ -192,7 +194,9 @@ NVIDIADriverDetector::getInstalledGraphicsDriverInfo(const std::string &packageN

LINGLONG_TRACE("Get installed NVIDIA graphics driver info");

GraphicsDriverInfo driverInfo{ getDriverIdentify(), packageName };
GraphicsDriverInfo driverInfo;
driverInfo.identify = getDriverIdentify();
driverInfo.packageName = packageName;

auto listResult = linglong::utils::Cmd("ll-cli").exec({ "--json", "list", "--type=extension" });
if (!listResult) {
Expand Down
2 changes: 2 additions & 0 deletions libs/linglong/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pfl_add_library(
src/linglong/runtime/container_builder.h
src/linglong/runtime/container.cpp
src/linglong/runtime/container.h
src/linglong/runtime/layer.cpp
src/linglong/runtime/layer.h
src/linglong/runtime/overlayfs_driver.cpp
src/linglong/runtime/overlayfs_driver.h
src/linglong/runtime/run_context.cpp
Expand Down
2 changes: 0 additions & 2 deletions libs/linglong/src/linglong/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@
#include "linglong/api/types/v1/UpgradeListResult.hpp"
#include "linglong/cdi/cdi.h"
#include "linglong/cli/printer.h"
#include "linglong/common/dir.h"

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/common/dir.h" not found.
#include "linglong/common/error.h"

Check warning on line 30 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/common/error.h" not found.
#include "linglong/common/strings.h"

Check warning on line 31 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/common/strings.h" not found.
#include "linglong/oci-cfg-generators/container_cfg_builder.h"
#include "linglong/package/layer_file.h"

Check warning on line 32 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/oci-cfg-generators/container_cfg_builder.h" not found.
#include "linglong/package/reference.h"

Check warning on line 33 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 34 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/package/reference.h" not found.
#include "linglong/runtime/container_builder.h"
#include "linglong/runtime/run_context.h"
#include "linglong/utils/bash_command_helper.h"
#include "linglong/utils/error/error.h"
#include "linglong/utils/file.h"
#include "linglong/utils/finally/finally.h"
#include "linglong/utils/gettext.h"

Check warning on line 41 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 42 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/gettext.h" not found.
#include "linglong/utils/runtime_config.h"

Check warning on line 43 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/namespace.h" not found.
#include "linglong/utils/xdg/directory.h"
#include "linglong/utils/xdp.h"

Check warning on line 44 in libs/linglong/src/linglong/cli/cli.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/runtime_config.h" not found.
#include "ocppi/runtime/ExecOption.hpp"
#include "ocppi/runtime/RunOption.hpp"
#include "ocppi/runtime/Signal.hpp"
Expand Down
1 change: 0 additions & 1 deletion libs/linglong/src/linglong/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "linglong/api/dbus/v1/task.h"
#include "linglong/api/types/v1/CommonOptions.hpp"
#include "linglong/api/types/v1/PackageInfoDisplay.hpp"
#include "linglong/api/types/v1/RepositoryCacheLayersItem.hpp"
#include "linglong/cli/interactive_notifier.h"
#include "linglong/cli/printer.h"
#include "linglong/common/serialize/json.h"
Expand Down
4 changes: 1 addition & 3 deletions libs/linglong/src/linglong/package_manager/package_task.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -15,8 +15,6 @@

#include <utility>

const auto TASK_DONE = 100;

namespace linglong::service {

PackageTask::PackageTask(std::function<void(Task &)> job, QObject *parent)
Expand Down
8 changes: 4 additions & 4 deletions libs/linglong/src/linglong/repo/ostree_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ OSTreeRepo::getRefStatistics(const RefMetaData &meta) const noexcept
}
g_clear_error(&gErr);

RefStatistics stat = { 0 };
RefStatistics stat{};

#if OSTREE_CHECK_VERSION(2020, 1)
g_autoptr(GPtrArray) sizes = NULL;
Expand Down Expand Up @@ -2100,12 +2100,12 @@ utils::error::Result<void> OSTreeRepo::exportDir(const std::string &appID,
&& common::strings::ends_with(target_path.string(), ".desktop")) {
auto desktopExists = false;
// 如果要导出的desktop已存在,则覆盖导出(无论是在default还是overlay中),避免桌面和任务栏的快捷方式失效
const std::string appDirs[] = { oldAppDir, newAppDir };
const std::array<std::string, 2> appDirs{ oldAppDir, newAppDir };
for (const auto &appDir : appDirs) {
// 如果目标文件存在,删除再导出
std::filesystem::path linkpath =
const std::filesystem::path linkpath =
target_path.string().replace(0, oldAppDir.string().length(), appDir);
auto status = std::filesystem::symlink_status(linkpath, ec);
std::ignore = std::filesystem::symlink_status(linkpath, ec);
if (!ec) {
desktopExists = true;
auto target = source_path.lexically_relative(linkpath.parent_path());
Expand Down
8 changes: 4 additions & 4 deletions libs/linglong/src/linglong/runtime/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <cassert>
#include <fstream>
#include <memory>
#include <utility>

#include <unistd.h>
Expand Down Expand Up @@ -143,10 +144,9 @@ auto ContainerContext::create(RunContext &context, CreateOptions options)
}
}

auto containerContext =
std::unique_ptr<ContainerContext>{ new ContainerContext(std::move(containerID),
std::move(*bundleDir),
std::move(options.appCache)) };
auto containerContext = std::make_unique<ContainerContext>(containerID,
std::move(*bundleDir),
std::move(options.appCache));

return containerContext;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/linglong/src/linglong/runtime/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ContainerContext
[[nodiscard]] auto getBundleDir() const -> const std::filesystem::path &;
[[nodiscard]] auto getContainerCache() const -> const std::optional<std::filesystem::path> &;
void addSecurityContext(std::unique_ptr<SecurityContext> securityContext);
auto setupOverlayFS(RunContext &context, bool readOnly) -> utils::error::Result<void>;
auto setupOverlayFS(RunContext &context, bool persistent) -> utils::error::Result<void>;
auto genLdConf(const std::string &ldConf, bool overlayEnabled) -> utils::error::Result<void>;

private:
Expand Down
17 changes: 8 additions & 9 deletions libs/linglong/src/linglong/runtime/container_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ auto getXDPDocumentsMountPoint() noexcept -> utils::error::Result<std::filesyste
return LINGLONG_ERR("Documents portal mount point reply is empty");
}

const auto &value = reply.arguments().constFirst();
auto arguments = reply.arguments();
const auto &value = arguments.constFirst();
if (!value.canConvert<QByteArray>()) {
return LINGLONG_ERR(
fmt::format("unexpected Documents portal mount point type: {}", value.typeName()));
Expand Down Expand Up @@ -306,7 +307,7 @@ auto ContainerBuilder::prepareContainer(runtime::RunContext &context,
}

PreparedContainer prepared{
.runContext = context,
.runContext = &context,
.context = std::move(*containerContext),
.mode = mode,
};
Expand All @@ -323,7 +324,7 @@ auto ContainerBuilder::prepareContainer(runtime::RunContext &context,
auto uid = getuid();
auto gid = getgid();

prepared.cfgBuilder.setAppId(prepared.runContext.get().getTargetID())
prepared.cfgBuilder.setAppId(prepared.runContext->getTargetID())
.setBundlePath(prepared.context->getBundleDir())
.addUIdMapping(uid, uid, 1)
.addGIdMapping(gid, gid, 1)
Expand Down Expand Up @@ -353,8 +354,7 @@ auto ContainerBuilder::finalizeContainer(PreparedContainer &prepared) noexcept
bool useOverlayMode = true;
bool needGenLdConf = false;
if (prepared.mode == ContainerMode::Init) {
auto &runContext = prepared.runContext.get();
const auto &appLayer = runContext.getAppLayer();
const auto &appLayer = prepared.runContext->getAppLayer();
if (!appLayer) {
return LINGLONG_ERR("app layer not found");
}
Expand Down Expand Up @@ -407,8 +407,7 @@ auto ContainerBuilder::configureBuildContainer(PreparedContainer &prepared,
prepared.cfgBuilder.isolateNetWork();
}

auto &runContext = prepared.runContext.get();
auto res = normalizeContainerRootfs(options.basePath, runContext.getConfig());
auto res = normalizeContainerRootfs(options.basePath, prepared.runContext->getConfig());
if (!res) {
return LINGLONG_ERR(res);
}
Expand Down Expand Up @@ -460,7 +459,7 @@ auto ContainerBuilder::configureInitContainer(PreparedContainer &prepared) noexc
{
LINGLONG_TRACE("configure init container");

auto &runContext = prepared.runContext.get();
auto &runContext = *prepared.runContext;

prepared.cfgBuilder.bindXDGRuntime().bindHostRoot().bindHostStatics().forwardDefaultEnv();

Expand Down Expand Up @@ -582,7 +581,7 @@ auto ContainerBuilder::configureRunContainer(PreparedContainer &prepared,
capabilities.insert(capabilities.end(), extraCapabilities.begin(), extraCapabilities.end());
prepared.cfgBuilder.setCapabilities(std::move(capabilities));

auto &runContext = prepared.runContext.get();
auto &runContext = *prepared.runContext;
for (const auto &type : options.getSecurityContexts()) {
auto manager = getSecurityContextManager(type);
if (!manager) {
Expand Down
4 changes: 2 additions & 2 deletions libs/linglong/src/linglong/runtime/container_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ContainerBuilder
-> utils::error::Result<std::unique_ptr<Container>>;

private:
enum class ContainerMode {
enum class ContainerMode : uint8_t {
Init,
Build,
Run,
Expand All @@ -104,7 +104,7 @@ class ContainerBuilder
struct PreparedContainer
{
generator::ContainerCfgBuilder cfgBuilder;
std::reference_wrapper<runtime::RunContext> runContext;
runtime::RunContext *runContext{ nullptr };
std::unique_ptr<ContainerContext> context;
ContainerMode mode{ ContainerMode::Run };
};
Expand Down
79 changes: 79 additions & 0 deletions libs/linglong/src/linglong/runtime/layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "linglong/runtime/layer.h"

#include "linglong/runtime/run_context.h"
#include "linglong/utils/log/log.h"

#include <fmt/ranges.h>

namespace linglong::runtime {
utils::error::Result<RuntimeLayer> RuntimeLayer::create(package::Reference ref,
const RunContext &context)
{
LINGLONG_TRACE(fmt::format("create runtime layer from ref {}", ref.toString()));

try {
return RuntimeLayer(std::move(ref), context);
} catch (const std::exception &e) {
return LINGLONG_ERR("failed to create runtime layer", e);
}
}

RuntimeLayer::RuntimeLayer(package::Reference ref, const RunContext &context)
: reference(std::move(ref))
, runContext(&context)
, temporary(false)
{
const auto &repo = context.getRepo();
auto item = repo.getLayerItem(reference);
if (!item) {
throw std::runtime_error("no cached item found");
}
cachedItem = std::move(item).value();
}

RuntimeLayer::~RuntimeLayer() noexcept
{
if (temporary && layerDir) {
std::error_code ec;
const auto &path = layerDir->path();
std::filesystem::remove_all(path, ec);
if (ec) {
LogI("failed to remove all files under {}: {}", path, ec.message());
}
}
}

utils::error::Result<void> RuntimeLayer::resolveLayer(const std::vector<std::string> &modules,
const std::optional<std::string> &subRef)
{
LINGLONG_TRACE("resolve layer");

if (this->runContext == nullptr) {
return LINGLONG_ERR("runContext is nullptr");
}

auto &repo = runContext->getRepo();
utils::error::Result<package::LayerDir> layer(LINGLONG_ERR("null"));
if (modules.empty() || (modules.size() == 1 && modules.at(0) == "binary")) {
layer = repo.getMergedModuleDir(reference, true, subRef);
} else if (modules.size() > 1) {
layer = repo.createTempMergedModuleDir(reference, modules);
temporary = true;
LogD("create temp merged module dir: {}", layer->path());
} else {
return LINGLONG_ERR(
fmt::format("resolve module {} is not supported", fmt::join(modules, ",")));
}

if (!layer) {
return LINGLONG_ERR("layer doesn't exist: " + reference.toString(), layer);
}

layerDir = *layer;
return LINGLONG_OK;
}
} // namespace linglong::runtime
74 changes: 74 additions & 0 deletions libs/linglong/src/linglong/runtime/layer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include "linglong/api/types/v1/RepositoryCacheLayersItem.hpp"
#include "linglong/package/layer_dir.h"
#include "linglong/package/reference.h"
#include "linglong/utils/error/error.h"

#include <functional>
#include <optional>
#include <string>
#include <vector>

namespace linglong::runtime {

class RunContext;

class RuntimeLayer
{
public:
RuntimeLayer(const RuntimeLayer &) = delete;
RuntimeLayer &operator=(const RuntimeLayer &) = delete;
RuntimeLayer(RuntimeLayer &&) = default;
RuntimeLayer &operator=(RuntimeLayer &&) = default;

static utils::error::Result<RuntimeLayer> create(package::Reference ref,
const RunContext &context);
~RuntimeLayer() noexcept;

struct ExtensionRuntimeLayerInfo
{
api::types::v1::ExtensionDefine extensionInfo;
std::reference_wrapper<RuntimeLayer> extensionLayer;
std::string forRef;
};

utils::error::Result<void>
resolveLayer(const std::vector<std::string> &modules = {},
const std::optional<std::string> &subRef = std::nullopt);

[[nodiscard]] const api::types::v1::RepositoryCacheLayersItem &getCachedItem() const noexcept
{
return cachedItem;
}

[[nodiscard]] const package::Reference &getReference() const noexcept { return reference; }

[[nodiscard]] const std::optional<package::LayerDir> &getLayerDir() const noexcept
{
return layerDir;
}

void setExtensionInfo(ExtensionRuntimeLayerInfo info) noexcept { extensionOf = info; }

[[nodiscard]] const std::optional<ExtensionRuntimeLayerInfo> &getExtensionInfo() const noexcept
{
return extensionOf;
}

private:
RuntimeLayer(package::Reference ref, const RunContext &context);

package::Reference reference;
const RunContext *runContext{ nullptr };
std::optional<package::LayerDir> layerDir;
api::types::v1::RepositoryCacheLayersItem cachedItem;
bool temporary{ false };
std::optional<ExtensionRuntimeLayerInfo> extensionOf;
};

}; // namespace linglong::runtime
Loading
Loading