-
Notifications
You must be signed in to change notification settings - Fork 48
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
base: master
Are you sure you want to change the base?
[Draft] fix: Create soft link for the watch file #593
Conversation
WalkthroughThe Changes
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
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 = {}, | ||
}); | ||
} |
There was a problem hiding this comment.
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:
- 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.
- 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. - 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.
- 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.
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 = {}, | |
}); | |
} |
546f72a
to
d7448b4
Compare
There was a problem hiding this 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
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
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: chenchongbiao, dengbo11 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 |
在容器运行时给容器内的监听文件创建软链接。文件修改后也能获取到修改。 Log:
d7448b4
to
8d62006
Compare
There was a problem hiding this 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
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
在容器运行时给容器内的监听文件创建软链接。文件修改后也能获取到修改。
Log:
Summary by CodeRabbit
New Features
Improvements