Skip to content

fix: ModifyId,假如新ID和旧ID的NonDX相同(例如5003->15003),会导致源文件被误删除且发生报错。#66

Merged
clansty merged 1 commit into
MuNET-OSS:mainfrom
Starrah:fix-modifyid
May 27, 2026
Merged

fix: ModifyId,假如新ID和旧ID的NonDX相同(例如5003->15003),会导致源文件被误删除且发生报错。#66
clansty merged 1 commit into
MuNET-OSS:mainfrom
Starrah:fix-modifyid

Conversation

@Starrah
Copy link
Copy Markdown
Collaborator

@Starrah Starrah commented May 27, 2026

如题,ModifyId,假如新ID和旧ID的NonDX相同(例如5003->15003),会导致源文件被误删除且发生报错。

之前的逻辑会计算新ID下文件移动到的目标路径,如果已经存在冲突的同名文件文件则删除之,再尝试移动旧ID下的文件过来。
那么当5003->15003时,目标计算出的还是ui_jacket_005003.jpg,于是这个“如果已经存在冲突的同名文件文件则删除之”的过程直接把源文件干掉了。

根据OPT中文件的排列规则,封面图、音频、视频用的都是nonDX四位ID,只有谱面music目录下用的六位长ID。所以当上述“新ID和旧ID的NonDX相同”的情况下,封面图、音频、视频根本不需要做任何移动。
所以把移动封面图、音频、视频的过程单独抽成一个函数,如果新ID和旧ID的NonDX相同则直接return、跳过移动它们的过程。谱面music则仍是每次正常移动。

Summary by Sourcery

通过将封面 / 音频 / 视频 的处理与谱面数据迁移分离,防止在新 ID 与旧 ID 具有相同非 DX 部分时,ModifyId 误删、误移动媒体文件。

Bug Fixes:

  • 在新旧 ID 具有相同非 DX 组成部分的 ID 变更过程中,避免误删源封面、音频和视频文件。

Enhancements:

  • 将媒体文件(封面 / 音频 / 视频)的迁移逻辑提取到一个由 ModifyId 调用的专用辅助方法中,从而与谱面文件处理实现更清晰的职责分离。
Original summary in English

Summary by Sourcery

Prevent ModifyId from incorrectly deleting and moving media files when the new ID shares the same non-DX portion as the old ID by separating jacket/audio/video handling from chart data migration.

Bug Fixes:

  • Avoid accidental deletion of source jacket, audio, and video files during ID changes where the new and old IDs have the same non-DX component.

Enhancements:

  • Extract media (jacket/audio/video) migration into a dedicated helper method invoked from ModifyId for clearer separation from chart file handling.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 27, 2026

Reviewer's Guide

通过将 jacket/audio/video(封面/音频/视频)的迁移逻辑抽取到一个辅助方法中,并在当新 ID 的 NonDx 部分未变化时提前返回,避免在像 5003→15003 这类共享相同 NonDx 的 ID 变更中意外删除源资源;同时在该路径下将 DeleteIfExists 的作用范围限制为仅非谱面(chart 以外)的资源,并将谱面文件夹清理逻辑单独处理。

更新后的 ModifyId 资源移动逻辑顺序图

sequenceDiagram
    participant Controller as MusicTransferController
    participant Settings as settings
    participant Music as MusicXmlWithABJacket

    Controller->>Settings: GetMusic(id, assetDir)
    Settings-->>Controller: Music
    alt music is null or license inactive
        Controller-->>Controller: return
    else valid music
        Controller->>Controller: DeleteIfExists(newMusicDir)
        Controller->>Controller: MoveJacketSoundVideo(music, newId, assetDir)
        activate Controller
        Controller->>Controller: [compute newNonDxId]
        alt newNonDxId == music.NonDxId
            Controller-->>Controller: return (skip jacket/audio/video move)
        else newNonDxId != music.NonDxId
            Controller->>Controller: DeleteIfExists(jacketTarget, soundTarget, movieTarget)
            Controller->>Controller: move jacket/audio/video files
        end
        deactivate Controller
        Controller->>Controller: move chart files (music directory)
    end
Loading

File-Level Changes

Change Details Files
将 jacket/audio/video 的移动逻辑抽取到一个独立的辅助方法中,当新 ID 与原始 ID 具有相同的 NonDx 部分时跳过处理,以避免错误删除。
  • 新增私有方法 MoveJacketSoundVideo(MusicXmlWithABJacket music, int newId, string assetDir),用于计算新的 NonDx ID 以及与封面、音频和视频相关的所有目标路径。
  • 在 MoveJacketSoundVideo 中增加提前返回逻辑:当 newNonDxId 等于 music.NonDxId 时,不删除或移动任何 jacket/audio/video 文件,因为它们的路径将保持一致。
  • 调整新辅助方法中的 DeleteIfExists,使其只针对 jacket、sound 和 movie 的输出路径,不再包含谱面所在的 music 目录,从而避免在处理 nonDX 资源时将其删除。
MaiChartManager/Controllers/Music/MusicTransferController.cs
简化 ModifyId,使其只负责验证音乐源目录、清理新的谱面目录,然后将 nonDX 资源处理委托给新的辅助方法。
  • 重新添加 ModifyId 作为一个 HttpPost action,通过 settings.GetMusic 获取 music,验证源 music 目录,并在路径无效时记录日志并抛出 DirectoryNotFoundException。
  • 将谱面目录清理修改为仅通过 DeleteIfExists 删除新的 music 目录(music{newId:000000}),并与 jacket/sound/video 的删除逻辑解耦。
  • 在 ModifyId 中调用 MoveJacketSoundVideo 处理 jacket/audio/video,同时保持后续分数(谱面)移动逻辑不变。
MaiChartManager/Controllers/Music/MusicTransferController.cs

Tips and commands

Interacting with Sourcery

  • 触发新一次代码审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 在某条审查评论下回复,请求 Sourcery 从该评论创建 issue。你也可以直接回复 @sourcery-ai issue 来生成对应的 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 总结: 在 pull request 的正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 总结。你也可以在 pull request 中评论 @sourcery-ai summary,在任意时间(重新)生成总结。
  • 生成审查者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审查者指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。如果你已经处理完所有评论且不希望再看到它们,这会很有用。
  • 一次性忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审查。特别适用于希望从头开始新一轮审查的情况 —— 别忘了再评论 @sourcery-ai review 触发新的审查!

Customizing Your Experience

访问你的 dashboard 来:

  • 启用或禁用审查特性,例如 Sourcery 生成的 pull request 总结、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查指令。
  • 调整其他审查设置。

Getting Help

Original review guide in English

Reviewer's Guide

Refactors ModifyId by extracting jacket/audio/video relocation into a helper that early-returns when the new ID’s NonDx portion is unchanged, preventing accidental deletion of source assets when IDs like 5003→15003 share the same NonDx, and limits DeleteIfExists in that path to only non-chart assets while handling chart folder cleanup separately.

Sequence diagram for updated ModifyId asset move logic

sequenceDiagram
    participant Controller as MusicTransferController
    participant Settings as settings
    participant Music as MusicXmlWithABJacket

    Controller->>Settings: GetMusic(id, assetDir)
    Settings-->>Controller: Music
    alt music is null or license inactive
        Controller-->>Controller: return
    else valid music
        Controller->>Controller: DeleteIfExists(newMusicDir)
        Controller->>Controller: MoveJacketSoundVideo(music, newId, assetDir)
        activate Controller
        Controller->>Controller: [compute newNonDxId]
        alt newNonDxId == music.NonDxId
            Controller-->>Controller: return (skip jacket/audio/video move)
        else newNonDxId != music.NonDxId
            Controller->>Controller: DeleteIfExists(jacketTarget, soundTarget, movieTarget)
            Controller->>Controller: move jacket/audio/video files
        end
        deactivate Controller
        Controller->>Controller: move chart files (music directory)
    end
Loading

File-Level Changes

Change Details Files
Extracted jacket/audio/video moving logic into a dedicated helper that skips work when the new ID shares the same NonDx portion as the original, avoiding erroneous deletions.
  • Introduced a private MoveJacketSoundVideo(MusicXmlWithABJacket music, int newId, string assetDir) method that computes the new NonDx ID and all related target paths for jackets, audio, and video.
  • Added an early return in MoveJacketSoundVideo when newNonDxId equals music.NonDxId so that no jacket/audio/video files are deleted or moved when their paths would be identical.
  • Adjusted DeleteIfExists in the new helper to only target jacket, sound, and movie outputs, no longer including the chart music directory so it is not removed as part of nonDX asset handling.
MaiChartManager/Controllers/Music/MusicTransferController.cs
Simplified ModifyId to validate the music source directory, clean up only the new chart directory, and then delegate nonDX asset handling to the new helper.
  • Re-added ModifyId as an HttpPost action that obtains the music via settings.GetMusic, validates the source music directory, and throws a DirectoryNotFoundException on invalid paths with logging.
  • Changed chart directory cleanup to only delete the new music directory (music{newId:000000}) via DeleteIfExists before moving charts, decoupled from jacket/sound/video deletion.
  • Invoked MoveJacketSoundVideo from ModifyId to handle jacket/audio/video processing while leaving the subsequent score (谱面) movement logic unchanged.
MaiChartManager/Controllers/Music/MusicTransferController.cs

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the ModifyId method in MusicTransferController.cs by extracting the asset-moving logic (jacket, sound, and video) into a helper method MoveJacketSoundVideo. It also skips moving these assets if the non-DX portion of the ID remains unchanged. A critical issue was identified where modifying an ID to the same value (id == newId) would delete the existing music directory, leading to data loss. A suggestion was made to return early in this case.

Comment thread MaiChartManager/Controllers/Music/MusicTransferController.cs
Copy link
Copy Markdown
Contributor

@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 - 我在这里给出了一些总体反馈:

  • MoveJacketSoundVideo 中的行内注释写的是 5003 -> 105003,而 PR 描述中写的是 5003 -> 15003;建议修改这个示例,以避免让人混淆到底是哪种模式真正有问题。
  • 现在关于夹克/音频/视频的处理已经被抽取到了 MoveJacketSoundVideo 中,你可以考虑把这部分逻辑移到一个专门的 service/helper 类中,而不是继续放在 controller 里,这样可以让 controller 的 action 更精简,更专注于 HTTP 相关的职责。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- The inline comment in `MoveJacketSoundVideo` mentions `5003 -> 105003` while the PR description uses `5003 -> 15003`; consider correcting this example to avoid confusion about which pattern is actually problematic.
- Now that the jacket/audio/video handling is extracted to `MoveJacketSoundVideo`, you might consider moving this logic into a dedicated service/helper class instead of keeping it on the controller to keep the controller action thin and focused on HTTP concerns.

Sourcery 对开源项目免费——如果你觉得我们的 Review 有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进之后的 Review。
Original comment in English

Hey - I've left some high level feedback:

  • The inline comment in MoveJacketSoundVideo mentions 5003 -> 105003 while the PR description uses 5003 -> 15003; consider correcting this example to avoid confusion about which pattern is actually problematic.
  • Now that the jacket/audio/video handling is extracted to MoveJacketSoundVideo, you might consider moving this logic into a dedicated service/helper class instead of keeping it on the controller to keep the controller action thin and focused on HTTP concerns.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The inline comment in `MoveJacketSoundVideo` mentions `5003 -> 105003` while the PR description uses `5003 -> 15003`; consider correcting this example to avoid confusion about which pattern is actually problematic.
- Now that the jacket/audio/video handling is extracted to `MoveJacketSoundVideo`, you might consider moving this logic into a dedicated service/helper class instead of keeping it on the controller to keep the controller action thin and focused on HTTP concerns.

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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-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.

1 issue found across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread MaiChartManager/Controllers/Music/MusicTransferController.cs
@clansty
Copy link
Copy Markdown
Member

clansty commented May 27, 2026

  • MoveJacketSoundVideo 中的行内注释写的是 5003 -> 105003,而 PR 描述中写的是 5003 -> 15003;建议修改这个示例,以避免让人混淆到底是哪种模式真正有问题。

这两种应该是一样的吧,一种是 dx 一种是宴谱

@Starrah
Copy link
Copy Markdown
Collaborator Author

Starrah commented May 27, 2026

  • MoveJacketSoundVideo 中的行内注释写的是 5003 -> 105003,而 PR 描述中写的是 5003 -> 15003;建议修改这个示例,以避免让人混淆到底是哪种模式真正有问题。

这两种应该是一样的吧,一种是 dx 一种是宴谱

逻辑上当然没有差别,现在我改完的代码也两种情况都能处理。

他的意思是我代码注释中举的例子,和commit message中举的例子,文字表述不一致。

@clansty clansty merged commit c4b0647 into MuNET-OSS:main May 27, 2026
1 check 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