`7zz rn arc d/ NEW` renames a directory to `NEWc.txt` (path separator lost); `rn d NEW` and `rn d/ NEW/` work

Aperta
#290 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Start in CPP/7zip/UI/Common/Update.cpp, especially CRenamePair::GetNewPath(), and compare how d NEW and d/ NEW build paths. Read the rename tests or add a focused regression case for both forms, including nested files. Done means rn d/ NEW preserves separators and produces the same archive paths as rn d NEW.

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

Descrizione

Environment

7-Zip (z) 26.06 (arm64), ip7z/7zip @ d3296e3, macOS 26.4.1 arm64

Steps to reproduce
d=$(mktemp -d) && cd "$d"
mkdir -p d/e; printf a > d/c.txt; printf b > d/e/f.txt
for spec in "d NEW" "d/ NEW" "d/ NEW/"; do
  rm -f t.7z; 7zz a -bd t.7z d > /dev/null
  7zz rn t.7z $spec > /dev/null; echo "rn $spec  rc=$?"
  7zz l -slt t.7z | grep '^Path = ' | tail -n +2 | tr '\n' ' '; echo
done

Output:

rn d NEW    rc=0   NEW  NEW/e  NEW/c.txt  NEW/e/f.txt        <- correct
rn d/ NEW   rc=0   NEW  NEWe   NEWc.txt   NEWe/f.txt         <- separator lost
rn d/ NEW/  rc=0   NEW/ NEW/e  NEW/c.txt  NEW/e/f.txt        <- correct
Expected

A trailing slash on the old name only marks it as a directory (7-Zip documents that "Slash at the end of a path means a directory"). rn d/ NEW should give the same result as rn d NEW.

Root cause (analysis on d3296e3)

CRenamePair::GetNewPath() in CPP/7zip/UI/Common/Update.cpp:317-339: CompareTwoNames returns the length of the matched prefix, which includes the trailing separator of OldName ("d/", 2 chars). The new path is built as dest = NewName + src.Ptr(num) (line 337), i.e. "NEW" + "c.txt". The separator that was consumed with the old prefix is not added after NewName. ArchiveCommandLine.cpp:500-523 stores the names unchanged and does not normalize trailing separators.

Suggested fix

Normalize both names the same way before building dest: strip a trailing separator from OldName and NewName for directory renames, or append a separator to NewName when the matched prefix of OldName ended with one.


Found with a differential test setup (a model of the documented behavior compared against the real binary) and then checked by hand: every command above was re-run verbatim on the tested build, and the root cause was read in the source. Tested commit: d3296e3 (26.06).

Lingua principale
C++
Stelle
4.6k
Fork
519
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 ip7z/7zip

Tutte le issue di ip7z/7zip

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.