fix(enable): use sysfs to detect wireless NIC instead of name prefix#668
fix(enable): use sysfs to detect wireless NIC instead of name prefix#668GongHeng2017 wants to merge 1 commit into
Conversation
Replace hardcoded name prefix matching (wlan/wlp) with sysfs path checking (/sys/class/net/<name>/wireless and phy80211) for more reliable wireless NIC detection. 使用 sysfs 路径检测替代硬编码名称前缀匹配来判断无线网卡,提升检测准确性。 Log: 修复无线网卡检测逻辑,使用sysfs替代名称前缀匹配 PMS: https://pms.uniontech.com/bug-view-362409.html Influence: 无线网卡启用/禁用操作不再依赖接口名称前缀,支持所有符合内核规范的无线网卡接口名称。
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors wireless network interface detection in EnableUtils to rely on sysfs entries instead of hardcoded interface name prefixes, and encapsulates the new detection logic in a private helper while updating metadata headers. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这份代码变更的主要目的是将原本通过硬编码字符串前缀( 以下是对本次代码变更的详细审查和改进意见: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议基于以上审查意见,建议对 bool EnableUtils::isWireless(const QString &logicalName)
{
// 安全校验:确保 logicalName 是合法的 Linux 网络接口名
// 合法字符仅包含字母、数字和下划线,且不为空,长度不超过 15 (IFNAMSIZ - 1)
static QRegularExpression validIfnameRegex("^[a-zA-Z0-9_]{1,15}$");
if (!validIfnameRegex.match(logicalName).hasMatch()) {
qWarning() << "Invalid logical name received:" << logicalName;
return false;
}
// 检查 /sys/class/net/<iface>/wireless 是否存在
// 在 Linux 中,只要存在 wireless 目录或 phy80211 链接,即可判定为无线网卡
// 优先检查 wireless,利用短路求值避免不必要的 QFileInfo 构造和 stat 调用
if (QFileInfo::exists(QString("/sys/class/net/%1/wireless").arg(logicalName))) {
return true;
}
// 备用检查 phy80211
return QFileInfo::exists(QString("/sys/class/net/%1/phy80211").arg(logicalName));
}改进点说明:
这个改进后的版本在安全性、健壮性和性能上都有所提升,且更符合 C++ 和 Qt 的最佳实践。 |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
isWirelesshelper can be simplified to a single return statement (e.g.,return wirelessInfo.exists() || phyInfo.exists();) to avoid the explicitif/elseand keep the code concise. - Consider using
QFile::exists()directly instead of constructingQFileInfoobjects inisWireless, since you only need to check existence and not other file metadata.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `isWireless` helper can be simplified to a single return statement (e.g., `return wirelessInfo.exists() || phyInfo.exists();`) to avoid the explicit `if/else` and keep the code concise.
- Consider using `QFile::exists()` directly instead of constructing `QFileInfo` objects in `isWireless`, since you only need to check existence and not other file metadata.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Replace hardcoded name prefix matching (wlan/wlp) with sysfs path checking (/sys/class/net//wireless and phy80211) for more reliable wireless NIC detection.
使用 sysfs 路径检测替代硬编码名称前缀匹配来判断无线网卡,提升检测准确性。
Log: 修复无线网卡检测逻辑,使用sysfs替代名称前缀匹配
PMS: https://pms.uniontech.com/bug-view-362409.html
Influence: 无线网卡启用/禁用操作不再依赖接口名称前缀,支持所有符合内核规范的无线网卡接口名称。
Summary by Sourcery
Detect wireless network interfaces via sysfs paths instead of hardcoded name prefixes when enabling or disabling devices.
Bug Fixes:
Enhancements: