Skip to content

fix(data-transfer): use JSON serialization for add_result and transfer_content messages - #780

Closed
pengfeixx wants to merge 1 commit into
linuxdeepin:release/v20from
pengfeixx:agent/pms-bug-bot/f1bd5337
Closed

pengfeixx wants to merge 1 commit into
linuxdeepin:release/v20from
pengfeixx:agent/pms-bug-bot/f1bd5337

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

fix(data-transfer): use JSON serialization for add_result and transfer_content messages

根因

数据传输完成后两端迁移完成列表不一致,接收端列表为空/严重缺失而发送端完整。

发送端以空格作为字段分隔符序列化迁移结果与传输进度(name + " " + success + " " + reason + ";"),但 name 与 reason 均为含空格的翻译文本。接收端按 split(" ") 严格校验 size()==3 / size()==4,当字段含空格时拆分结果字段数超限,continue 丢弃该条目。全部 11 处 addResult 的 reason 均含空格,故缺陷 100% 必现。

修复方案

将空格分隔的自定义格式替换为 JSON 结构化序列化(QJsonDocument),两端格式严格同步,字段边界不再依赖内容是否含空格:

add_result

  • 发送端 resultdisplay.cpp:processText 改为 QJsonArray,addResult() 构造 QJsonObject{name, success, reason} 追加到数组,transferFinished 时以 QJsonDocument::Compact 序列化发送。
  • 接收端 transferworker.cpp:QJsonDocument::fromJson 解析数组,逐项 emit addResult。

transfer_content(同模式一并修复)

  • 发送端 transferringwidget.cpp:构造 QJsonObject{type, content, progressbar, estimatedtime} → 紧凑 JSON 发送。
  • 接收端 transferworker.cpp:解析 JSON(兼容单对象与数组),逐项 emit transferContent。

涉及文件

  • src/plugins/data-transfer/core/gui/transfer/resultdisplay.h
  • src/plugins/data-transfer/core/gui/transfer/resultdisplay.cpp
  • src/plugins/data-transfer/core/gui/transfer/transferringwidget.cpp
  • src/plugins/data-transfer/core/utils/transferworker.cpp

边界情况

  • 空字段:JSON 空字符串合法,无影响。
  • 含空格/特殊字符的 name/reason/filepath:JSON 字符串自动转义,无分隔符冲突。
  • 空列表:序列化为 [],接收端安全遍历。
  • transfer_content 接收端兼容单对象与数组,增强健壮性。

基线

  • 分支:release/v20
  • 基线 full-sha:570cb50b4f7bb810b9483e3277e2e5199add58c5

Log: PMS bug 246975

Summary by Sourcery

Use JSON serialization for add-result and transfer-content messages to preserve message fields reliably across data-transfer endpoints.

Bug Fixes:

  • Prevent data-transfer result and progress messages from being dropped when names, reasons, or content contain spaces or special characters.

Enhancements:

  • Replace delimiter-based serialization with structured JSON for migration results and transfer progress, while accepting both object and array forms for transfer-content messages.

…r_content messages

The send side serialized migration results and transfer progress using
space-delimited fields (name + " " + success + " " + reason + ";"), but
both name and reason are translated strings that contain spaces. The
receive side split on " " with a strict size()==3 / size()==4 check,
which discarded every entry, causing the receiver's completion list to
be empty while the sender's was complete.

Replace the space-delimited format with JSON (QJsonDocument) on both
sides so field boundaries are unambiguous regardless of content:
- add_result: sender builds a QJsonArray of {name, success, reason}
  objects; receiver parses the array and emits addResult per entry.
- transfer_content: sender builds a single {type, content, progressbar,
  estimatedtime} object; receiver parses it (handling both single object
  and array) and emits transferContent.

Log: PMS bug 246975

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

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

@github-actions

Copy link
Copy Markdown

CLA Assistant Lite bot:

如果你是以企业贡献者的身份进行提交,请联系我们签署企业贡献者许可协议
If you submit as corporate contributor, please contact us to sign our Corporate Contributor License Agreement

感谢您的提交,我们非常感谢。 像许多开源项目一样,在接受您的贡献之前,我们要求您签署我们的个人贡献者许可协议。 您只需发布与以下格式相同的评论即可签署个人贡献者许可协议。
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Individual Contributor License Agreement before we can accept your contribution. You can sign the Individual Contributor License Agreement by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA.

Multica Agent seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@sourcery-ai

sourcery-ai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Switches the data-transfer IPC protocol for add_result and transfer_content from ad-hoc space-separated strings to structured JSON using QJsonDocument/QJsonArray/QJsonObject on both sender and receiver sides, eliminating parsing failures when fields contain spaces and adding minor robustness for transfer_content handling.

Sequence diagram for JSON data-transfer IPC messages

sequenceDiagram
    participant ResultDisplayWidget
    participant TransferringWidget
    participant TransferHelper
    participant TransferHandle
    participant ResultWindow

    ResultDisplayWidget->>ResultDisplayWidget: addResult(name, success, reason)
    ResultDisplayWidget->>ResultWindow: updateContent(name, reason, success)
    ResultDisplayWidget->>TransferHelper: sendMessage(add_result, QJsonDocument(processText))
    TransferHelper->>TransferHandle: handleMiscMessage(jsonmsg)
    TransferHandle->>TransferHandle: QJsonDocument::fromJson(result)
    TransferHandle-->>TransferHelper: addResult(name, success, reason)

    TransferringWidget->>TransferHelper: sendMessage(transfer_content, QJsonDocument(obj))
    TransferHelper->>TransferHandle: handleMiscMessage(jsonmsg)
    TransferHandle->>TransferHandle: QJsonDocument::fromJson(result)
    TransferHandle-->>TransferHelper: transferContent(type, content, progressbar, estimatedtime)
Loading

File-Level Changes

Change Details Files
Replace space-delimited string aggregation of transfer results with JSON array of result objects and serialize via QJsonDocument when transfer finishes.
  • Change ResultDisplayWidget::processText from QString accumulator to QJsonArray member field.
  • Update ResultDisplayWidget::addResult to build a QJsonObject with name/success/reason and append to the QJsonArray instead of concatenating a formatted string.
  • Modify the transferFinished lambda to send a compact JSON serialization of the QJsonArray via TransferHelper::sendMessage("add_result", …).
  • Include necessary Qt JSON headers for resultdisplay code.
src/plugins/data-transfer/core/gui/transfer/resultdisplay.h
src/plugins/data-transfer/core/gui/transfer/resultdisplay.cpp
Parse add_result messages as JSON on the receiving side and emit addResult for each element of the array.
  • Add Qt JSON headers to transferworker implementation.
  • In TransferHandle::handleMiscMessage, replace string splitting logic for add_result with QJsonDocument::fromJson and iteration over a JSON array of objects.
  • For each JSON object, read name/success/reason fields and emit TransferHelper::addResult accordingly.
  • Retain transferFinished emit after processing the array.
src/plugins/data-transfer/core/utils/transferworker.cpp
Serialize transfer_content updates as a JSON object instead of a space-delimited string on the sender side.
  • In TransferringWidget::updateProcess, replace manual construction of a space-separated status string with creation of a QJsonObject containing type, content, progressbar, and estimatedtime.
  • Serialize the JSON object in compact form via QJsonDocument and send it with TransferHelper::sendMessage("transfer_content", …).
  • Include Qt JSON headers in transferringwidget implementation.
src/plugins/data-transfer/core/gui/transfer/transferringwidget.cpp
Parse transfer_content messages as JSON on the receiving side, supporting both single-object and array payloads for robustness.
  • In TransferHandle::handleMiscMessage, replace string splitting logic for transfer_content with QJsonDocument::fromJson over the received payload.
  • Treat a JSON array as the primary form; if the document is an object, append it into a QJsonArray for uniform handling.
  • For each JSON object, read type/content/progressbar/estimatedtime and emit TransferHelper::transferContent.
  • Remove size-based validation tied to space-delimited parsing, relying on JSON structure instead.
src/plugins/data-transfer/core/utils/transferworker.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

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