fix: Fix fail to get device info#162
Conversation
- Refactor command execution code to use a unified API with separated program name and parameter list. - Update .gitignore to include additional files and directories. - Remove unused watcher class and related code to streamline the service. Log: Fix fail to get device info Bug: https://pms.uniontech.com/bug-view-303363.html
|
TAG Bot TAG: 6.0.10 |
deepin pr auto review代码审查意见:
总体来说,这些修改提高了代码的健壮性、可读性和可维护性,是一个积极的改进。 |
Reviewer's GuideRefactors external process handling to use a unified Utils API with error handling and argument parsing, removes unused Watcher code, updates D-Bus invocations, enhances logging and safety checks, and updates .gitignore. Sequence diagram for unified external command execution via Utils::executCmdsequenceDiagram
participant Caller
participant Utils
participant QProcess
Caller->>Utils: executCmd(strCmd, outPut, error)
Utils->>Utils: parseCombinedArgString(strCmd)
Utils->>QProcess: start(prog, args)
QProcess-->>Utils: process output/error
Utils-->>Caller: exit code, outPut, error
Sequence diagram for MainWindow closing and D-Bus quit signalsequenceDiagram
actor User
participant MainWindow
participant QProcess
User->>MainWindow: closeEvent()
MainWindow->>QProcess: startDetached("/usr/bin/dbus-send", argList)
QProcess-->>MainWindow: (detached)
MainWindow-->>User: window closes
Sequence diagram for PartedCore device info retrieval with error handlingsequenceDiagram
participant PartedCore
participant Utils
participant QProcess
PartedCore->>Utils: executCmd(cmd, outPut, error)
Utils->>QProcess: start(prog, args)
QProcess-->>Utils: process output/error
Utils-->>PartedCore: exit code, outPut, error
alt exit code != 0
PartedCore->>PartedCore: log error, return early
else exit code == 0
PartedCore->>PartedCore: process output
end
ER diagram for removal of Watcher entityerDiagram
WATCHER ||--o{ DISKMANAGERSERVICE : monitored_by
%% The WATCHER entity and its relationships have been removed.
Class diagram for updated Utils process execution APIclassDiagram
class Utils {
+static int executCmd(const QString &strCmd, QString &outPut, QString &error)
+static int executCmd(const QString &strCmd)
+static int executeCmdWithArtList(const QString &strCmd, const QStringList &strArgList, QString &outPut, QString &error)
+static int executWithInputOutputCmd(const QString &strCmdArg, const QString *inPut, QString &outPut, QString &error)
+static QString readContent(const QString &filename)
+static QString findProgramInPath(const QString &proName)
}
Utils : +static QStringList parseCombinedArgString(const QString &program)
Class diagram for removed Watcher classclassDiagram
class Watcher {
+void start()
+void exit()
}
%% Watcher class and its methods have been removed from the codebase.
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @wangrong1069 - I've reviewed your changes - here's some feedback:
- In main.cpp the custom executCmd still uses naive strCmd.split(" ") instead of the new parseCombinedArgString logic—consider unifying argument parsing across all executCmd uses for consistent quoted‐arg handling.
- There’s a recurring pattern of calling Utils::executCmd then checking exit codes and logging errors in many methods—extracting that into a small wrapper helper would reduce boilerplate and improve maintainability.
- The literal "UnKnow" return value in getDiskInfoMediaType looks like a typo and a magic string; consider using a constant or enum (e.g. "Unknown") to ensure consistency and avoid mistakes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In main.cpp the custom executCmd still uses naive strCmd.split(" ") instead of the new parseCombinedArgString logic—consider unifying argument parsing across all executCmd uses for consistent quoted‐arg handling.
- There’s a recurring pattern of calling Utils::executCmd then checking exit codes and logging errors in many methods—extracting that into a small wrapper helper would reduce boilerplate and improve maintainability.
- The literal "UnKnow" return value in getDiskInfoMediaType looks like a typo and a magic string; consider using a constant or enum (e.g. "Unknown") to ensure consistency and avoid mistakes.
## Individual Comments
### Comment 1
<location> `service/diskoperation/DeviceStorage.cpp:666` </location>
<code_context>
- QString outPut = proc.readAllStandardOutput().trimmed();
- value = outPut;
+ QString rotational_file = QString("/sys/block/%1/queue/rotational").arg(device);
+ QString value = Utils::readContent(rotational_file).trimmed();
if ("1" == value) {
</code_context>
<issue_to_address>
No error handling for readContent failures.
Explicitly check for file read errors to avoid ambiguity between an unreadable file and valid values.
</issue_to_address>
### Comment 2
<location> `service/diskoperation/partedcore.cpp:174` </location>
<code_context>
}
- // qDebug() << __FUNCTION__ << "Get Device Hard Info end";
+ qDebug() << "Get device hard info for " << devicepath;
+ qDebug() << "Model: " << hdinfo.m_model;
+ qDebug() << "Vendor: " << hdinfo.m_vendor;
</code_context>
<issue_to_address>
Consider adding a toString() or QDebug operator<< to HardDiskInfo and replacing multiple qDebug() statements with a single call.
```cpp
// 1) Add a toString() (or QDebug operator<<) to HardDiskInfo:
class HardDiskInfo {
public:
// ...
QString toString() const {
return QStringLiteral(
"Model: %1, Vendor: %2, MediaType: %3, Size: %4, RotationRate: %5, "
"Interface: %6, SerialNumber: %7, Version: %8, Capabilities: %9, "
"Description: %10, PowerOnHours: %11, PowerCycleCount: %12, "
"FirmwareVersion: %13, Speed: %14")
.arg(m_model, m_vendor, m_mediaType, m_size, m_rotationRate,
m_interface, m_serialNumber, m_version, m_capabilities,
m_description, QString::number(m_powerOnHours),
QString::number(m_powerCycleCount),
m_firmwareVersion, m_speed);
}
};
// (Optional) If you prefer streaming directly to QDebug:
inline QDebug operator<<(QDebug dbg, const HardDiskInfo &info) {
dbg.nospace() << info.toString();
return dbg.space();
}
// 2) Replace the 15+ qDebug() calls in getDeviceHardInfo with a single line:
HardDiskInfo PartedCore::getDeviceHardInfo(const QString &devicepath) {
// ... populate hdinfo ...
qDebug() << "GetDeviceHardInfo for" << devicepath << ":" << hdinfo;
return hdinfo;
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| qDebug() << "value is 1"; | ||
| cmd = QString("smartctl -i %1").arg(devicePath); | ||
| proc.start(cmd); | ||
| proc.waitForFinished(-1); |
There was a problem hiding this comment.
suggestion (bug_risk): No error handling for readContent failures.
Explicitly check for file read errors to avoid ambiguity between an unreadable file and valid values.
| } | ||
|
|
||
| // qDebug() << __FUNCTION__ << "Get Device Hard Info end"; | ||
| qDebug() << "Get device hard info for " << devicepath; |
There was a problem hiding this comment.
issue (complexity): Consider adding a toString() or QDebug operator<< to HardDiskInfo and replacing multiple qDebug() statements with a single call.
// 1) Add a toString() (or QDebug operator<<) to HardDiskInfo:
class HardDiskInfo {
public:
// ...
QString toString() const {
return QStringLiteral(
"Model: %1, Vendor: %2, MediaType: %3, Size: %4, RotationRate: %5, "
"Interface: %6, SerialNumber: %7, Version: %8, Capabilities: %9, "
"Description: %10, PowerOnHours: %11, PowerCycleCount: %12, "
"FirmwareVersion: %13, Speed: %14")
.arg(m_model, m_vendor, m_mediaType, m_size, m_rotationRate,
m_interface, m_serialNumber, m_version, m_capabilities,
m_description, QString::number(m_powerOnHours),
QString::number(m_powerCycleCount),
m_firmwareVersion, m_speed);
}
};
// (Optional) If you prefer streaming directly to QDebug:
inline QDebug operator<<(QDebug dbg, const HardDiskInfo &info) {
dbg.nospace() << info.toString();
return dbg.space();
}
// 2) Replace the 15+ qDebug() calls in getDeviceHardInfo with a single line:
HardDiskInfo PartedCore::getDeviceHardInfo(const QString &devicepath) {
// ... populate hdinfo ...
qDebug() << "GetDeviceHardInfo for" << devicepath << ":" << hdinfo;
return hdinfo;
}|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wangrong1069 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 |
|
/merge |
Log: Fix fail to get device info
Bug: https://pms.uniontech.com/bug-view-303363.html
Summary by Sourcery
Refactor shell command execution to use a unified Utils::executCmd API with argument parsing and error handling; replace direct QProcess calls throughout the service and application, add detailed logging, remove the unused Watcher component, and update .gitignore.
Enhancements:
Build:
Chores: