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

Abierto
#206 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

@rahul05ranjan ya está trabajando en esto.

Desde el 28/10/2026.

  • #207 de @rahul05ranjan — abierto
  • #210 de @Lushiyao5 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
268
Forks
25
Merge medio
4 d 11 h
PR fusionados (30 d)
2

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de fabiocaccamo/python-fsutil

Todos los issues de fabiocaccamo/python-fsutil

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.