fix(storage): initialize default save path to Downloads instead of home#728
Open
re2zero wants to merge 1 commit intolinuxdeepin:masterfrom
Open
fix(storage): initialize default save path to Downloads instead of home#728re2zero wants to merge 1 commit intolinuxdeepin:masterfrom
re2zero wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: re2zero 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 |
SessionManager._save_root was empty until storageConfig signal arrived, which depended on signal connection timing via std::call_once. On fresh installs with no config, the signal never fired and files were saved to home directory instead of Downloads. SessionManager._save_root 在 storageConfig 信号到达前为空,而该信号 依赖 std::call_once 的时序。新安装系统无历史配置时信号不触发,导致文件 保存在主目录而非下载目录。 Log: 修复新安装系统文件保存路径默认为主目录的问题 PMS: BUG-296181 Influence: 新安装镜像上接收文件将正确保存在下载目录,而非主目录。已安装系统行为不受影响。
fc5112e to
d5738b0
Compare
deepin pr auto review这份代码变更主要涉及两个文件的修改,主要是关于存储路径的调整。我将从语法逻辑、代码质量、代码性能和代码安全四个方面进行详细审查。 1. 语法逻辑审查config.h 修改点:
networkutil.cpp 修改点:
2. 代码质量审查优点:
改进建议:
3. 代码性能审查
4. 代码安全审查潜在问题:
改进建议代码config.h 改进建议: const fastring getStorageDir() const
{
// 使用标准API获取下载目录,避免硬编码
fastring download = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation).toStdString();
// 确保目录存在
if (!os::exists(download)) {
os::mkdir(download, true); // 递归创建目录
}
if (_targetName.empty()) {
return download;
} else {
return path::join(download, _targetName);
}
}networkutil.cpp 改进建议: NetworkUtilPrivate::NetworkUtilPrivate(NetworkUtil *qq)
: q_ptr(qq)
{
LOG << "This is only transfer?" << onlyTransfer;
sessionManager = new SessionManager(this);
// 获取并验证下载目录
QString downloadDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
if (downloadDir.isEmpty()) {
LOG << "Warning: Failed to get download directory, fallback to home directory";
downloadDir = QDir::homePath();
}
// 确保目录存在
QDir dir(downloadDir);
if (!dir.exists()) {
if (!dir.mkpath(".")) {
LOG << "Error: Failed to create download directory";
}
}
sessionManager->setStorageRoot(downloadDir);
if (onlyTransfer) {
DLOG << "Running in transfer-only mode, skipping full initialization";
return;
}
// ... 其余代码
}总结
这些改进将使代码更加健壮、可移植和安全。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SessionManager._save_roottoDownloadLocationinNetworkUtilPrivateconstructor, eliminating dependency onstorageConfigsignal timingDaemonConfig::getStorageDir()fallback fromhomedir()topath::join(home, "Downloads")for compat daemonRoot Cause
PMS Bug #296181 — 新安装镜像上通过文管投送文件后,文件保存在主目录而非下载目录,必现。
5-Why 分析:
_save_root(SessionManager) 和storagedir(DaemonConfig) 未被正确设置NetworkUtil::updateStorageConfig()从未被调用(依赖storageConfig信号)deviceInfo()中通过std::call_once触发,但可能在connect之前执行DaemonConfig::getStorageDir()fallback 是homedir()而非Downloads为什么之前修复两次仍被激活: 打开设置对话框会自动写入默认路径并触发信号链,"修复"了问题。开发者本地无法复现是因为已有历史配置。
Test Plan
~/Downloads/设备名(IP)/~/Downloads~/Downloads/