Skip to content

Conversation

@Johnson-zs
Copy link
Contributor

@Johnson-zs Johnson-zs commented Jan 23, 2026

Added local file validation before attempting to create FileInfo objects for property dialog. Previously, the code would try to create FileInfo for any URL path without checking if it's a local file, which could cause issues with non-local file paths. Now only local files are processed for property dialog display, preventing potential crashes or errors when handling remote or special URLs.

Log: Fixed property dialog opening failure with non-local file paths

Influence:

  1. Test opening property dialog with local files - should work normally
  2. Test with remote URLs (ftp, http) - should skip gracefully without errors
  3. Test with invalid local paths - should show warning and skip
  4. Verify that valid local files still display property dialog correctly
  5. Check console logs for proper warning messages when skipping non- local files

fix: 在属性对话框创建文件信息前检查是否为本地文件

添加了本地文件验证,在尝试为属性对话框创建FileInfo对象之前进行检查。之
前代码会为任何URL路径尝试创建FileInfo,而不检查是否为本地文件,这可能导
致处理远程或特殊URL时出现问题。现在只有本地文件会被处理用于属性对话框显
示,防止处理远程URL时出现潜在崩溃或错误。

Log: 修复了使用非本地文件路径时属性对话框打开失败的问题

Influence:

  1. 测试使用本地文件打开属性对话框 - 应正常工作
  2. 测试使用远程URL(ftp、http) - 应优雅跳过且不报错
  3. 测试使用无效本地路径 - 应显示警告并跳过
  4. 验证有效的本地文件仍能正确显示属性对话框
  5. 检查控制台日志,确保跳过非本地文件时有正确的警告信息

Bug: https://pms.uniontech.com/bug-view-348227.html

Summary by Sourcery

Bug Fixes:

  • Prevent property dialog failures when invoked with non-local or invalid file paths by skipping non-local URLs and logging warnings.

Added local file validation before attempting to create FileInfo
objects for property dialog. Previously, the code would try to create
FileInfo for any URL path without checking if it's a local file, which
could cause issues with non-local file paths. Now only local files are
processed for property dialog display, preventing potential crashes or
errors when handling remote or special URLs.

Log: Fixed property dialog opening failure with non-local file paths

Influence:
1. Test opening property dialog with local files - should work normally
2. Test with remote URLs (ftp, http) - should skip gracefully without
errors
3. Test with invalid local paths - should show warning and skip
4. Verify that valid local files still display property dialog correctly
5. Check console logs for proper warning messages when skipping non-
local files

fix: 在属性对话框创建文件信息前检查是否为本地文件

添加了本地文件验证,在尝试为属性对话框创建FileInfo对象之前进行检查。之
前代码会为任何URL路径尝试创建FileInfo,而不检查是否为本地文件,这可能导
致处理远程或特殊URL时出现问题。现在只有本地文件会被处理用于属性对话框显
示,防止处理远程URL时出现潜在崩溃或错误。

Log: 修复了使用非本地文件路径时属性对话框打开失败的问题

Influence:
1. 测试使用本地文件打开属性对话框 - 应正常工作
2. 测试使用远程URL(ftp、http) - 应优雅跳过且不报错
3. 测试使用无效本地路径 - 应显示警告并跳过
4. 验证有效的本地文件仍能正确显示属性对话框
5. 检查控制台日志,确保跳过非本地文件时有正确的警告信息

Bug: https://pms.uniontech.com/bug-view-348227.html
@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 23, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a local-file check before creating FileInfo objects in the property dialog command parser so that only local, existing files are processed, preventing errors or crashes when handling remote or invalid URLs.

Sequence diagram for property dialog file validation flow

sequenceDiagram
    participant User
    participant CommandParser
    participant QUrl
    participant InfoFactory
    participant FileInfo

    User->>CommandParser: showPropertyDialog(paths)
    loop for each path in paths
        CommandParser->>QUrl: fromUserInput(path)
        QUrl-->>CommandParser: url
        alt url.isLocalFile is false
            CommandParser->>CommandParser: skip url (no FileInfo created)
        else url.isLocalFile is true
            CommandParser->>QUrl: isLocalFile()
            CommandParser->>InfoFactory: create_FileInfo(url)
            InfoFactory-->>CommandParser: fileInfo
            alt !fileInfo or !fileInfo.exists
                CommandParser->>CommandParser: log warning invalid path or file not exists
                CommandParser->>CommandParser: continue
            else valid local file
                CommandParser->>CommandParser: add url to urlList
            end
        end
    end
    CommandParser->>CommandParser: open property dialog for urlList
Loading

Class diagram for updated CommandParser property dialog logic

classDiagram
    class CommandParser {
        +showPropertyDialog()
        -QStringList paths
        -QList~QUrl~ urlList
    }

    class QUrl {
        +fromUserInput(path)
        +isLocalFile() bool
        +path() QString
    }

    class InfoFactory {
        +create_FileInfo(url) FileInfoPointer
    }

    class FileInfo {
        +exists() bool
    }

    class FileInfoPointer {
        +operator*() FileInfo
        +operator->() FileInfo*
    }

    CommandParser --> QUrl : uses
    CommandParser --> InfoFactory : uses
    InfoFactory --> FileInfoPointer : creates
    FileInfoPointer --> FileInfo : points_to
    CommandParser --> FileInfo : checks_exists
Loading

File-Level Changes

Change Details Files
Guard FileInfo creation in property dialog with a local-file check to avoid processing remote or invalid URLs.
  • Wrap FileInfo creation in a QUrl::isLocalFile() condition when iterating over command-line paths.
  • Keep the existing existence/validity check for FileInfo but apply it only to local files.
  • Preserve non-local URLs by skipping FileInfo creation while still allowing their URLs to be added to the urlList (behavior to be confirmed in review).
  • Retain the existing warning log message for invalid or non-existent local paths.
src/apps/dde-file-manager/commandparser.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这段代码的修改主要是增加了对 url.isLocalFile() 的检查,这是一个很好的改进。以下是对这段代码的详细审查意见:

1. 语法逻辑

  • 改进点:增加了 url.isLocalFile() 判断,逻辑更加严谨。原来的代码对所有类型的 URL 都会尝试创建 FileInfo 并检查是否存在,这对于非本地文件(如网络地址)可能是不必要的或错误的。
  • 建议:当前的逻辑是只对本地文件进行存在性检查,这是合理的。但需要确认对于非本地文件(如 smb://, ftp:// 等),后续代码(QString uPath = url.path();)是否能正确处理。

2. 代码质量

  • 改进点:增加了条件判断,使代码意图更清晰。
  • 建议:可以考虑将 FileInfoPointer 的声明移到 if 块内部,以限制其作用域,避免不必要的引用:
    if (url.isLocalFile()) {
        FileInfoPointer fileInfo = InfoFactory::create<FileInfo>(url);
        if (!fileInfo || !fileInfo->exists()) {
            qCWarning(logAppFileManager) << "Failed to show property dialog: invalid path or file not exists -" << path;
            continue;
        }
    }

3. 代码性能

  • 改进点:通过 isLocalFile() 提前过滤,避免了对非本地文件进行不必要的 InfoFactory::create 操作,减少了不必要的文件系统访问。
  • 潜在问题QUrl::fromUserInput 本身可能有一定的开销,如果 paths 列表很大,可以考虑优化 URL 的解析方式。

4. 代码安全

  • 改进点:增加了对 URL 类型的检查,避免了对非本地文件进行不适当的操作。
  • 潜在风险
    • 如果 url.path() 用于非本地文件,可能需要额外的处理逻辑(如网络路径的特殊处理)。
    • 建议确认 InfoFactory::create<FileInfo> 是否线程安全,如果这段代码可能被多线程调用,需要考虑加锁。

5. 其他建议

  • 日志记录:对于非本地文件,是否需要记录日志或提示用户?当前代码对非本地文件静默跳过检查,可能需要明确告知用户某些路径被忽略。
  • 错误处理:如果 url.isLocalFile() 返回 false 但后续代码依赖本地文件路径,可能会导致问题。建议检查后续代码是否正确处理非本地文件。

总结

这段代码的改进是合理的,主要增加了对 URL 类型的检查,提高了代码的健壮性。建议进一步确认后续代码对非本地文件的处理逻辑,并考虑优化变量作用域和日志记录。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The current change only guards FileInfo creation for local files but still allows non-local QUrls to fall through the loop; if the intent is to skip non-local URLs entirely for the property dialog, consider explicitly continue-ing (and optionally logging) when !url.isLocalFile().
  • The warning message is only emitted for invalid local paths now; if remote or special URLs are being skipped by design, you may want a separate log path so operators can distinguish between "non-local URL skipped" and "local path invalid or missing".
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The current change only guards FileInfo creation for local files but still allows non-local QUrls to fall through the loop; if the intent is to skip non-local URLs entirely for the property dialog, consider explicitly `continue`-ing (and optionally logging) when `!url.isLocalFile()`.
- The warning message is only emitted for invalid local paths now; if remote or special URLs are being skipped by design, you may want a separate log path so operators can distinguish between "non-local URL skipped" and "local path invalid or missing".

## Individual Comments

### Comment 1
<location> `src/apps/dde-file-manager/commandparser.cpp:229-230` </location>
<code_context>
-        if (!fileInfo || !fileInfo->exists()) {
-            qCWarning(logAppFileManager) << "Failed to show property dialog: invalid path or file not exists -" << path;
-            continue;
+        if (url.isLocalFile()) {
+            const FileInfoPointer &fileInfo = InfoFactory::create<FileInfo>(url);
+            if (!fileInfo || !fileInfo->exists()) {
+                qCWarning(logAppFileManager) << "Failed to show property dialog: invalid path or file not exists -" << path;
+                continue;
</code_context>

<issue_to_address>
**question (bug_risk):** Non-local URLs now bypass existence validation and logging; confirm this behavior is intended.

Previously every `path` went through `InfoFactory::create<FileInfo>(url)` and an existence check, which also logged invalid/non-existent inputs (including any non-local schemes `InfoFactory` supports). With the `url.isLocalFile()` guard, non-local URLs now skip this validation and logging and go straight to `url.path()`/`urlList`, so invalid remote/virtual URLs may reach downstream logic without diagnostics. Consider adding explicit handling for non-local URLs here or clearly relying on validation later in the pipeline.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +229 to +230
if (url.isLocalFile()) {
const FileInfoPointer &fileInfo = InfoFactory::create<FileInfo>(url);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Non-local URLs now bypass existence validation and logging; confirm this behavior is intended.

Previously every path went through InfoFactory::create<FileInfo>(url) and an existence check, which also logged invalid/non-existent inputs (including any non-local schemes InfoFactory supports). With the url.isLocalFile() guard, non-local URLs now skip this validation and logging and go straight to url.path()/urlList, so invalid remote/virtual URLs may reach downstream logic without diagnostics. Consider adding explicit handling for non-local URLs here or clearly relying on validation later in the pipeline.

@Johnson-zs
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 25, 2026

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 50930d5 into linuxdeepin:master Jan 25, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants