-
Notifications
You must be signed in to change notification settings - Fork 43
fix(watch): fix path format and add watch for newly created directories #331
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
Conversation
Reviewer's GuideEnsures filesystem watcher paths match the format from getDesktopFileDirs(), guarantees watched directories exist (creating them if needed), and dynamically adds a watcher when the user applications directory is created during addUserApplication(). Sequence diagram for updated directory watch initialization in initServicesequenceDiagram
participant AMS as ApplicationManager1Service
participant FSW as QFileSystemWatcher_m_watcher
participant Util as getDesktopFileDirs
participant QD as QDir
participant FS as FileSystem
AMS->>Util: getDesktopFileDirs()
Util-->>AMS: desktopDirs
loop ensure_each_directory_exists
AMS->>QD: QDir(dirPath)
AMS->>QD: exists()
alt directory_missing
AMS->>QD: mkpath(dirPath)
alt mkpath_success
QD-->>AMS: true
AMS->>FS: create_directory(dirPath)
else mkpath_failure
QD-->>AMS: false
AMS-->>AMS: log_warning_failed_to_create
end
else directory_exists
QD-->>AMS: true
end
end
AMS->>FSW: addPaths(desktopDirs)
FSW-->>AMS: unhandled_paths
loop log_unhandled_paths
AMS-->>AMS: log_critical_could_not_watch
end
AMS->>FSW: connect(directoryChanged, ReloadApplications)
Sequence diagram for updated addUserApplication directory creation and watchsequenceDiagram
participant Client as D-Bus_Client
participant AMS as ApplicationManager1Service
participant Env as getXDGDataHome
participant QD as QDir
participant FSW as QFileSystemWatcher_m_watcher
participant FS as FileSystem
Client->>AMS: addUserApplication(desktopInfo)
AMS->>Env: getXDGDataHome()
Env-->>AMS: xdgDataHomePath
AMS-->>AMS: dir = xdgDataHomePath
AMS-->>AMS: ensure_trailing_separator(dir)
AMS-->>AMS: dir.append("applications")
AMS->>QD: QDir(dir)
AMS->>QD: exists()
QD-->>AMS: dirExisted
AMS->>QD: mkpath(dir)
alt mkpath_failure
QD-->>AMS: false
AMS-->>Client: sendErrorReply(could_not_create_directory)
AMS-->>AMS: return
else mkpath_success
QD-->>AMS: true
alt directory_newly_created
AMS->>FSW: directories()
FSW-->>AMS: watchedDirs
AMS-->>AMS: check !dirExisted && !watchedDirs.contains(dir)
alt needs_watch
AMS->>FSW: addPath(dir)
alt watch_added
FSW-->>AMS: true
AMS-->>AMS: log_info_added_watch
else watch_failed
FSW-->>AMS: false
AMS-->>AMS: log_warning_failed_to_add_watch
end
else already_watched_or_existed
AMS-->>AMS: no_additional_watch
end
else directory_previously_existed
AMS-->>AMS: no_additional_watch
end
AMS-->>AMS: continue_to_create_or_update_desktop_file
AMS-->>Client: return_desktop_file_path_or_id
end
Updated class diagram for ApplicationManager1Service directory watching logicclassDiagram
class ApplicationManager1Service {
- QFileSystemWatcher m_watcher
+ void initService(QDBusConnection connection)
+ QString addUserApplication(QVariantMap desktopInfo)
}
class QFileSystemWatcher {
+ QStringList directories()
+ QStringList addPaths(QStringList paths)
+ bool addPath(QString path)
+ void directoryChanged(QString path)
}
class QDir {
+ QDir(QString path)
+ bool exists()
+ bool mkpath(QString dirPath)
+ void setPath(QString path)
+ QString filePath(QString fileName)
}
class QDBusConnection {
}
class Helpers {
+ QStringList getDesktopFileDirs()
+ QString getXDGDataHome()
}
ApplicationManager1Service --> QFileSystemWatcher : uses_m_watcher
ApplicationManager1Service --> QDBusConnection : uses
ApplicationManager1Service --> QDir : uses
ApplicationManager1Service --> Helpers : calls
QFileSystemWatcher --> ApplicationManager1Service : emits_directoryChanged_to_ReloadApplications
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey - I've left some high level feedback:
- When ensuring directories exist in initService, consider using QDir().mkpath(dirPath) or dir.mkpath(".") instead of dir.mkpath(dirPath) to avoid the confusing pattern of a QDir constructed with dirPath then being asked to mkpath the same absolute path.
- To reduce subtle mismatches when comparing and watching paths (e.g., m_watcher.directories().contains(dir)), normalize directory strings with QDir::cleanPath (and possibly consistent trailing separator handling) before comparisons and addPath/addPaths calls.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When ensuring directories exist in initService, consider using QDir().mkpath(dirPath) or dir.mkpath(".") instead of dir.mkpath(dirPath) to avoid the confusing pattern of a QDir constructed with dirPath then being asked to mkpath the same absolute path.
- To reduce subtle mismatches when comparing and watching paths (e.g., m_watcher.directories().contains(dir)), normalize directory strings with QDir::cleanPath (and possibly consistent trailing separator handling) before comparisons and addPath/addPaths calls.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Ensure directories exist before adding watches and fix path format consistency to match getDesktopFileDirs(). Dynamically add watch for newly created application directories. 修复目录路径格式问题,并在添加监听前确保目录存在。为动态创建的应用目录添加监听。 Log: 修复目录监听问题 PMS: BUG-340395 Influence: 修复了路径格式不一致导致的目录监听失败问题,确保新创建的应用目录能被正确监听,避免应用更新后无法及时刷新。
deepin pr auto review这份代码 diff 主要涉及对 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与修改建议代码以下是结合上述建议的优化版本代码片段: 修改
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mhduiy, 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 |
|
/merge |
Ensure directories exist before adding watches and fix path format consistency to match getDesktopFileDirs(). Dynamically add watch for newly created application directories.
修复目录路径格式问题,并在添加监听前确保目录存在。为动态创建的应用目录添加监听。
Log: 修复目录监听问题
PMS: BUG-340395
Influence: 修复了路径格式不一致导致的目录监听失败问题,确保新创建的应用目录能被正确监听,避免应用更新后无法及时刷新。
Summary by Sourcery
Ensure application directories are consistently watched by normalizing paths, creating missing directories, and dynamically adding watches for newly created ones.
Bug Fixes:
Enhancements: