Clean up temp repos when manage reset or finish-reset fails

オープン
#29 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
api, backend

調査の方向性

Start with the reset and FinishReset handlers in the manage API, along with GetTempRepoPath, InitRepoAt, SoftDeleteRepo, CleanupRepoFolder and DeleteRepoIfExists, which the issue names. Check whether the repo exists before InitRepoAt runs in reset, and wrap the temp-directory work in FinishReset so a failure deletes _____temp_____/{code}__upload__{ts}. Done means both failure paths leave no temp directory behind and the 404 and error responses are unchanged.

索引モデルが issue の本文から書いたものです。

説明

Two manage operations leave a directory behind in _____temp_____ when they fail partway through.

1. POST /api/manage/repos/{code}/reset on a repo that doesn't exist

var tmpRepo = new DirectoryInfo(GetTempRepoPath(code, "reset"));
await InitRepoAt(tmpRepo, cancellationToken);            // creates _____temp_____/{code}__reset__{ts}
await SoftDeleteRepo(code, ResetSoftDeleteSuffix(...));  // throws DirectoryNotFoundException -> 404
tmpRepo.MoveTo(PrefixRepoFilePath(code));                // never reached

The caller gets a 404, but the freshly initialised temp repo is never cleaned up.

2. POST /api/manage/repos/{code}/finish-reset with a corrupt or invalid zip

FinishReset creates _____temp_____/{code}__upload__{ts} and then extracts into it. If ExtractToDirectory throws (bad zip, InvalidDataException, IO error, cancellation), the partially extracted directory stays behind. Only the "no .hg folder" path deletes it. The same is true for exceptions thrown later in the method, for example from CleanupRepoFolder or DeleteRepoIfExists.

Nothing cleans up _____temp_____, so these accumulate on the volume (a failed upload can be large).

Suggested fix: wrap both in try/catch (or finally with a success flag) that deletes the temp directory on failure. For reset, check that the repo exists before running InitRepoAt.

Note: this logic is a port of LexBox's HgService, which has the same behaviour today, so LexBox will keep this behaviour when it switches to /api/manage unless it's fixed here.

主要言語
C#
スター
0
フォーク
1
平均マージ
1日 6時間
マージ済み PR(30日)
3

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sillsdev/hgresume のほかの issue

sillsdev/hgresume の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。