fix(phrase-service): 修正暫存檔清理寬限期判斷順序反轉#50
Merged
Merged
Conversation
CleanupPhraseTempFiles 原本先判斷是否為本服務命名格式,只有「非本服務」 的殘留檔案才套用寬限期;管理格式(本服務建立)的暫存檔會跳過寬限期直接 刪除。這與 AppSettings.CleanupConfigTempFiles 的參考實作相反,會造成兩個 問題:自我重啟時新舊行程重疊窗口期內,另一實例剛註冊尚未寫完的暫存檔可能 被立即刪除;而非本服務的殘留檔案過了寬限期後反而會被誤刪,違反「清理流程 只能刪除已不活躍且屬於本服務命名格式殘留檔案」的邊界。 調整為與 AppSettings.cs 一致的順序:非本服務命名格式一律略過,管理格式的 檔案才檢查寬限期,通過後才刪除。
StopVibration() 在非 MTA 執行緒(如 UI 執行緒呼叫 Pause/Dispose 時)會以 Task.Run 觸發背景執行緒呼叫 SetRumbleState 後立即返回,未等待馬達歸零指令 實際送達即視為完成。這與規範要求的「必須具備同步 StopVibration(),支援 緊急清理」、「視窗關閉時馬達立即停止」不一致,理論上若行程在背景工作完成 前即終止,控制器可能短暫殘留震動。 在該分支補上 GetAwaiter().GetResult() 阻塞等待背景 MTA 執行緒完成歸零指令, 使呼叫端取得的同步保證與馬達實際歸零時序一致;COM 存取仍發生於背景執行緒, 不影響原有的 MTA 執行緒親和性設計。 順帶隨附一併修正本檔結尾多餘換行,使其符合 .editorconfig 的 insert_final_newline = false。
.editorconfig 對 *.cs 設定 insert_final_newline = false,但 20 個檔案結尾 多出一個換行字元,導致 dotnet format --verify-no-changes 回報 FINALNEWLINE 違規。以 dotnet format whitespace 重新套用格式,純空白字元異動、無邏輯變更。
Contributor
There was a problem hiding this comment.
Pull request overview
本 PR 修正 PhraseService.CleanupPhraseTempFiles 的清理判斷順序,使其與 AppSettings.CleanupConfigTempFiles 的行為一致:只處理本服務命名格式(managed)的暫存檔,並且 managed 暫存檔也必須先通過寬限期 才會刪除,以避免重啟/多實例窗口期內誤刪仍在寫入流程中的暫存檔。
Changes:
- 非本服務命名格式的暫存檔一律略過(不再套用寬限期後誤刪)。
- managed 暫存檔改為先檢查寬限期,通過後才刪除(避免新鮮暫存檔被立即刪除)。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
CleanupPhraseTempFiles 原本先判斷是否為本服務命名格式,只有「非本服務」
的殘留檔案才套用寬限期;管理格式(本服務建立)的暫存檔會跳過寬限期直接
刪除。這與 AppSettings.CleanupConfigTempFiles 的參考實作相反,會造成兩個 問題:自我重啟時新舊行程重疊窗口期內,另一實例剛註冊尚未寫完的暫存檔可能
被立即刪除;而非本服務的殘留檔案過了寬限期後反而會被誤刪,違反「清理流程
只能刪除已不活躍且屬於本服務命名格式殘留檔案」的邊界。
調整為與 AppSettings.cs 一致的順序:非本服務命名格式一律略過,管理格式的
檔案才檢查寬限期,通過後才刪除。