Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] fix: Create soft link for the watch file #593

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chenchongbiao
Copy link
Collaborator

@chenchongbiao chenchongbiao commented Jul 17, 2024

在容器运行时给容器内的监听文件创建软链接。文件修改后也能获取到修改。

Log:

Summary by CodeRabbit

  • New Features

    • Enhanced the container runtime to support automatic symlinking and mount updates for specified files.
  • Improvements

    • Improved configuration management with additional mount configurations based on user-specified file paths.

Copy link

coderabbitai bot commented Jul 17, 2024

Walkthrough

The Container::run function in container.cpp has been enhanced to support file symlinking and dynamic mount updates via the new member variable, watchFilesPaths. This allows the function to iterate over specified paths, create symlinks to a designated directory, and update the configuration object (cfg) with new mounts, ensuring the container's runtime environment accurately reflects the necessary file structures.

Changes

Files Change Summary
libs/linglong/src/linglong/runtime/container.cpp Enhanced Container::run to implement file symlinking and mount updates based on watchFilesPaths.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Container
    participant FileSystem
    participant Config

    User->>Container: Calls run(process)
    Container->>FileSystem: Iterates over watchFilesPaths
    loop Symlink each file
        FileSystem->>Container: Return symlink status
    end
    Container->>Config: Update mounts with new symlinks
    Config-->>Container: Mounts updated
    Container-->>User: Run completed
Loading

Poem

In the land of code, where changes dwell,
A rabbit hops with tales to tell.
Symlinks bloom, mounts arise,
In containers, no surprise.
Watch the paths, let files align,
Configurations now divine.
Hoppy tweaks in coding's light,
Make the runtime clean and bright. 🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7f96e5c and 546f72a.

Files selected for processing (1)
  • libs/linglong/src/linglong/runtime/container.cpp (1 hunks)

Comment on lines 208 to 191
QStringList watchFilesPaths = {"localtime", "resolv.conf", "timezone"};
for (const QString &watchFile: watchFilesPaths) {
symlink("/run/host/monitor/"+watchFile.toUtf8(), bundle.absoluteFilePath(watchFile).toUtf8());
this->cfg.mounts->push_back(ocppi::runtime::config::types::Mount{
.destination = "/etc/"+watchFile.toStdString(),
.gidMappings = {},
.options = { { "rbind", "copy-symlink" } },
.source = bundle.absoluteFilePath(watchFile).toStdString(),
.type = "bind",
.uidMappings = {},
});
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Symlink creation and mount updates in Container::run.

The loop correctly iterates over watchFilesPaths to create symlinks and update mounts. However, there are several considerations:

  1. Security: Ensure that the paths used in symlinks do not lead to unintended exposures or vulnerabilities. Using absolute paths can mitigate risks associated with relative path traversal.
  2. Error Handling: The code does not handle potential errors from the symlink function. It's crucial to check if the symlink creation succeeds and handle failures appropriately to avoid runtime issues.
  3. Performance: While the loop handles a fixed list of paths, consider the implications if this list grows. Ensure that the operations within the loop are optimized for larger datasets.
  4. Maintainability: The loop is straightforward but consider encapsulating this logic into a separate method if the symlink and mount logic becomes more complex in the future.
for (const QString &watchFile: watchFilesPaths) {
-    symlink("/run/host/monitor/"+watchFile.toUtf8(), bundle.absoluteFilePath(watchFile).toUtf8());
+    if (symlink("/run/host/monitor/"+watchFile.toUtf8(), bundle.absoluteFilePath(watchFile).toUtf8()) != 0) {
+        qCritical() << "Failed to create symlink for" << watchFile;
+        continue; // Optionally handle the error more gracefully
+    }
    this->cfg.mounts->push_back(ocppi::runtime::config::types::Mount{
        .destination = "/etc/"+watchFile.toStdString(),
        .gidMappings = {},
        .options = { { "rbind", "copy-symlink" } },
        .source = bundle.absoluteFilePath(watchFile).toStdString(),
        .type = "bind",
        .uidMappings = {},
    });
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
QStringList watchFilesPaths = {"localtime", "resolv.conf", "timezone"};
for (const QString &watchFile: watchFilesPaths) {
symlink("/run/host/monitor/"+watchFile.toUtf8(), bundle.absoluteFilePath(watchFile).toUtf8());
this->cfg.mounts->push_back(ocppi::runtime::config::types::Mount{
.destination = "/etc/"+watchFile.toStdString(),
.gidMappings = {},
.options = { { "rbind", "copy-symlink" } },
.source = bundle.absoluteFilePath(watchFile).toStdString(),
.type = "bind",
.uidMappings = {},
});
}
QStringList watchFilesPaths = {"localtime", "resolv.conf", "timezone"};
for (const QString &watchFile: watchFilesPaths) {
if (symlink("/run/host/monitor/"+watchFile.toUtf8(), bundle.absoluteFilePath(watchFile).toUtf8()) != 0) {
qCritical() << "Failed to create symlink for" << watchFile;
continue; // Optionally handle the error more gracefully
}
this->cfg.mounts->push_back(ocppi::runtime::config::types::Mount{
.destination = "/etc/"+watchFile.toStdString(),
.gidMappings = {},
.options = { { "rbind", "copy-symlink" } },
.source = bundle.absoluteFilePath(watchFile).toStdString(),
.type = "bind",
.uidMappings = {},
});
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 546f72a and d7448b4.

Files selected for processing (1)
  • libs/linglong/src/linglong/runtime/container.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/linglong/src/linglong/runtime/container.cpp

@deepin-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: chenchongbiao, dengbo11
Once this PR has been reviewed and has the lgtm label, please assign black-desk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

在容器运行时给容器内的监听文件创建软链接。文件修改后也能获取到修改。

Log:
@dengbo11 dengbo11 force-pushed the 20240716-ln-monitor branch from d7448b4 to 8d62006 Compare July 22, 2024 06:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d7448b4 and 8d62006.

Files selected for processing (1)
  • libs/linglong/src/linglong/runtime/container.cpp (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • libs/linglong/src/linglong/runtime/container.cpp

@dengbo11 dengbo11 changed the title fix: Create soft link for the watch file Draft fix: Create soft link for the watch file Jul 25, 2024
@dengbo11 dengbo11 changed the title Draft fix: Create soft link for the watch file fix: Create soft link for the watch file Jul 25, 2024
@dengbo11 dengbo11 changed the title fix: Create soft link for the watch file [Draft] fix: Create soft link for the watch file Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants