Skip to content

fix(prelude): unsuppress glob in os.dirs by escaping shell metachars#15

Merged
Sunrisepeak merged 1 commit intomainfrom
fix/os-dirs-glob-quoting
May 5, 2026
Merged

fix(prelude): unsuppress glob in os.dirs by escaping shell metachars#15
Sunrisepeak merged 1 commit intomainfrom
fix/os-dirs-glob-quoting

Conversation

@Sunrisepeak
Copy link
Copy Markdown
Member

Summary

os.dirs(pattern) shells out to ls -d "<pattern>" 2>/dev/null on POSIX. Wrapping the pattern in double quotes makes the shell skip glob expansion entirely — ls -d "/tmp/x/cuda_v*" looks for a literal file named cuda_v* and returns nothing.

Reproduced upstream:

$ mkdir -p /tmp/x/cuda_v12 /tmp/x/cuda_v13
$ ls -d "/tmp/x/cuda_v*"      # ← double-quoted: glob suppressed
ls: cannot access '/tmp/x/cuda_v*': No such file or directory
$ ls -d /tmp/x/cuda_v*         # ← unquoted: shell expands
/tmp/x/cuda_v12  /tmp/x/cuda_v13

Any xpkg package using os.dirs("…/v*") to enumerate installed versions silently returned an empty list.

Fix

Replace the all-quote approach with a per-character backslash escape that preserves glob meta (* ? [ ] ~) while still escaping whitespace, $, backticks, quotes, and shell redirect/control chars. ls -d then receives an unquoted pattern that the shell expands, and paths with spaces still survive.

Windows branch unchanged: cmd.exe's built-in dir does its own pattern matching on the argument, so the existing quoted form there is correct.

Test plan

  • xmake build clean
  • All 27 xpkg_executor_test cases pass
  • Local shell verification: glob expands for /tmp/x/cuda_v*, escaped space /tmp/x\ space/cuda_v* still works
  • CI green (multi-platform)

`os.dirs(pattern)` used `ls -d "<pattern>" 2>/dev/null` on POSIX. Wrapping
the pattern in double quotes makes the shell skip glob expansion entirely
— `ls -d "/tmp/x/cuda_v*"` looks for a literal file named `cuda_v*` and
returns nothing. Reproduced by upstream user.

Fix: replace the all-quote approach with a per-character backslash escape
that preserves glob meta (`* ? [ ] ~`) while still quoting whitespace,
$, backticks, and shell redirects/control chars. Now `ls -d` receives an
unquoted pattern that the shell expands as expected, and paths with
spaces still survive.

Windows branch unchanged: cmd.exe `dir` does its own pattern matching on
the argument, so the existing quoted form there is correct.
@Sunrisepeak Sunrisepeak merged commit 247e2e2 into main May 5, 2026
3 checks passed
@Sunrisepeak Sunrisepeak deleted the fix/os-dirs-glob-quoting branch May 5, 2026 00:03
Sunrisepeak added a commit that referenced this pull request May 5, 2026
The cppm is auto-generated by xmake `before_build` from src/lua-stdlib/*
but also tracked in git as a snapshot. PR #15 updated prelude.lua but
left the committed snapshot stale — builds work because xmake regenerates
at build time, but the diff is misleading. Re-run the embed and commit
the result so HEAD matches what a fresh build would produce.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant