get_unique_name appends to the previous candidate name when a collision triggers a retry

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

メンテナーはふだん 1 日以内に返信

@rahul05ranjan がすでに取り組んでいます。

2026年10月28日 から。

  • #207 @rahul05ranjan による — オープン
  • #210 @Lushiyao5 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
backend

調査の方向性

Start in the implementation of fsutil.get_unique_name() and inspect how the candidate name is built before the exists() check. The issue suggests reproducing the collision with sequential UUIDs and checking that a retry builds a fresh candidate; the suggested regression test can verify the second name. Two linked pull requests are already open.

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

説明

Summary

fsutil.get_unique_name() builds the candidate name with += while the name is initialized to "" outside the retry loop:

name = ""
while True:
    if prefix:
        name += f"{prefix}{separator}"
    uid = uuid.uuid4()
    name += f"{uid}"
    ...
    if exists(join_path(path, name)):
        continue
    break

When the exists() check finds a collision and continues, the candidate is not rebuilt from scratch: the next prefix/uuid/suffix/extension are appended onto the previous (already colliding) candidate, producing a garbage name like:

prefix-<uid1>-suffix.txtprefix-<uid2>-suffix.txt

instead of

prefix-<uid2>-suffix.txt

This is hard to hit with random uuid4 values, but the loop exists precisely to handle collisions (e.g. when a caller passes a monkeypatched/sequential uuid source, or get_unique_name is reused as a generic "find unused name" helper by replace_dir / replace_file which rely on it for safe temporary names).

Suggested fix

Move name = "" inside the while True: loop so every retry starts clean. Adding a regression test is easy by monkeypatching fsutil.paths.uuid.uuid4 to a sequential iterator and creating the first candidate on disk before the second call.

Happy to send a PR.

主要言語
Python
スター
268
フォーク
25
平均マージ
20時間 48分
マージ済み PR(30日)
1

環境構築

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

はじめの一歩

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

fabiocaccamo/python-fsutil のほかの issue

fabiocaccamo/python-fsutil の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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