Skip to content

fix: only rewrite whole Windows reserved device names - #2704

Open
Pranav-IIITM wants to merge 1 commit into
buildpacks:mainfrom
Pranav-IIITM:fix-reserved-names-substring
Open

Pranav-IIITM wants to merge 1 commit into
buildpacks:mainfrom
Pranav-IIITM:fix-reserved-names-substring

Conversation

@Pranav-IIITM

Copy link
Copy Markdown

Summary

paths.FilterReservedNames rewrote valid names because it matched the Windows reserved words (aux, com, con, lpt, nul, prn) as substrings, and it ran on every OS. As a result, ordinary names were mangled — including on Linux and macOS, where no names are reserved — which changed the Docker cache volume names users actually asked for.

Before / After

                     before                after
my-company-cache  -> my-c_o_mpany-cache -> my-company-cache
connection-cache  -> c_o_nnection-cache -> connection-cache
config            -> c_o_nfig           -> config
nul   (Windows)   -> n_u_l              -> n_u_l
nul.txt (Windows) -> n_u_l.txt          -> n_u_l.txt
nul   (Linux/mac) -> n_u_l              -> nul   (unchanged)

What changed

  • Skip the transformation entirely on non-Windows platforms — these names are only reserved on Windows.
  • Match the whole base name (the part before the first .), case-insensitively, instead of matching a reserved word anywhere in the string.
  • Use the accurate Windows reserved set: CON, PRN, AUX, NUL, COM1–COM9, LPT1–LPT9. Bare com/lpt are no longer rewritten, since they are not actually reserved.
  • Preserve original casing and any extension, so nul.txt becomes n_u_l.txt.
  • Replace the old test that asserted the substring behavior with cases covering Windows reserved names, Windows ordinary names, and the non-Windows no-op.

Impact

  • Cache volume names now match what the user requested, so they are recognizable in docker volume ls and via scripting.
  • A user-pre-created volume whose name merely contains a reserved word (e.g. my-company-cache) is no longer missed.
  • Ordinary names are no longer needlessly rewritten on Linux and macOS.

Migration note

Existing incorrectly mangled volumes are not renamed automatically. After upgrading, pack may reference a new, correctly named volume while the old mangled volume remains until it is cleaned up manually.

Testing

  • go build ./internal/paths/...
  • go vet ./internal/paths/
  • go test ./internal/paths/... ./pkg/cache/...

Closes #2703

FilterReservedNames matched reserved words (aux, com, con, lpt, nul,
prn) as substrings and ran on every OS, so valid names were mangled
(e.g. "my-company-cache" -> "my-c_o_mpany-cache", "config" ->
"c_o_nfig"), including on Linux and macOS where nothing is reserved.
This changed Docker cache volume names away from what users requested.

Match only the whole base name, case-insensitively, against the actual
Windows reserved set (CON, PRN, AUX, NUL, COM1-COM9, LPT1-LPT9), handle
names with an extension such as "nul.txt", and skip the transformation
entirely on non-Windows platforms.

Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
@Pranav-IIITM
Pranav-IIITM requested review from a team as code owners September 28, 2026 14:28
@github-actions github-actions Bot added the type/enhancement Issue that requests a new feature or improvement. label Sep 28, 2026
@github-actions github-actions Bot added this to the 0.41.0 milestone Sep 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement Issue that requests a new feature or improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cache volume names are mangled

1 participant