Skip to content

fix: handle rm -rf * on Windows not matching files with shopt -u failglob#162

Merged
dsherret merged 6 commits intodenoland:mainfrom
wolfv:rm-rf-nonexistent
Jan 20, 2026
Merged

fix: handle rm -rf * on Windows not matching files with shopt -u failglob#162
dsherret merged 6 commits intodenoland:mainfrom
wolfv:rm-rf-nonexistent

Conversation

@wolfv
Copy link
Contributor

@wolfv wolfv commented Jan 13, 2026

We had a user report that rm -rf *.nonexistent fails even though -f should just ignore non-existent files.

Apparently it's related to how pattern expansion fails when not matching any files before it even reaches rm. This changes the behavior to keep the original (literal) pattern if nothing matches and hands that to rm.

Written by Claude Code and tested against bash behavior.

Original issue: prefix-dev/pixi#3969

@dsherret
Copy link
Member

deno_task_shell uses shopt -s failglob behaviour so this is by design.

$ shopt -s failglob
$ rm *.non-existent
-bash: no match: *.non-existent

Basically the glob gets evaluated before reaching the rm command. This behaviour is desirable in most cases because it prevents mistakes, but with the rm command it's not so ideal.

I'm not sure what should be done here, but maybe we should support config with shopt. This works atm, but I think it's a bug rm *.non-existent 2> /dev/null || true because glob expansion is supposed to be evaluated first (this errors in bash with shopt -s failglob)

@wolfv
Copy link
Contributor Author

wolfv commented Jan 15, 2026

Hey @dsherret thanks for the reply! I wasn't aware that this is by design, and I do think that for the rm -rf ... case it's definitely a bit problematic.

I would also say that it might be good to make failglob at least configurable (so we could decide in Pixi what we want). Happy to try a PR or extend this one if you want.

@dsherret dsherret changed the title fix rm -rf * failing on non-existent files fix: handle rm -rf * on Windows with shopt -u failglob Jan 20, 2026
@dsherret dsherret reopened this Jan 20, 2026
@dsherret dsherret changed the title fix: handle rm -rf * on Windows with shopt -u failglob fix: handle rm -rf * on Windows not matching files with shopt -u failglob Jan 20, 2026
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dsherret dsherret merged commit ee99672 into denoland:main Jan 20, 2026
4 checks passed
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.

2 participants