Package archive builder deletes existing file with unsupported suffix under --force

Aperta Adatta ai principianti
#57,727 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@akhil9tiet ci sta già lavorando.

Dal 28/10/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, rust
Ambito
cli, testing

Direzione di ricerca

Leggi scripts/codex_package/archive.py e segui write_archive() dalla convalida del formato dell’archivio fino all’eliminazione del file; scripts/codex_package/cli.py mostra il chiamante pubblico. Aggiungi un caso di regressione in scripts/codex_package/test_archive.py usando un file esistente con un’estensione non supportata e force=True; il lavoro è completato quando il comando rifiuta l’estensione e conserva il file.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Summary

scripts/codex_package/archive.py::write_archive() deletes an existing --archive-output file when --force is supplied before validating the archive filename suffix. If the suffix is unsupported, the command fails with RuntimeError, but the pre-existing file has already been removed.

This is observable through the public package builder: scripts/codex_package/cli.py::archive_package() resolves each --archive-output and calls write_archive(..., force=args.force). The CLI accepts any path at argument parsing time.

Reproduction (isolated, no build required)

Using write_archive with an empty package directory and a pre-existing non-archive file:

from pathlib import Path
from tempfile import TemporaryDirectory
from codex_package.archive import write_archive

with TemporaryDirectory() as tmp:
    root = Path(tmp)
    package = root / "package"
    package.mkdir()
    output = root / "important.txt"
    output.write_text("keep this data")
    try:
        write_archive(package, output, force=True)
    except RuntimeError as exc:
        print(exc)  # Unsupported archive suffix ...
    assert output.read_text() == "keep this data"  # FAILS: FileNotFoundError

Set CODEX_REPO_ROOT to the repository root before importing the package, as required by codex_package.targets.

Expected

Reject unsupported archive suffixes without changing the existing output file.

Actual

write_archive runs archive_path.unlink() before archive_format_for_path(archive_path), so the original file is deleted even though no archive is written.

Evidence / verification

Reviewed scripts/codex_package/archive.py, scripts/codex_package/cli.py, scripts/codex_package/test_archive.py, and scripts/codex_package/test_cli.py at commit e742db9f7ba98e63e502b310857d49d047888518; rechecked the same order on the current default branch. An isolated local Python reproduction of the exact initial write_archive control flow confirmed the file disappears after the unsupported-suffix exception. Existing tests cover zstd resolution and version parsing, but not this failure case.

Suggested fix

Validate archive_format_for_path(archive_path) before any unlink/write side effects, and add a regression test asserting that a pre-existing file with an unsupported suffix is preserved when force=True.

No pull request has been submitted.

Lingua principale
Rust
Stelle
131k
Fork
20.7k
Merge medio
1m
PR unite (30g)
997

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/codex

Tutte le issue di openai/codex

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.