From 2ee3538de45cdbfd7ec62c449f534574fd3d7a96 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:15:53 -0600 Subject: [PATCH] fix `du` `--exclude` globbing bug (#12093) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR fixes a globbing bug in the `du` command. The problem was that `--exclude` needed to be a `NuGlob` instead of a `String`. A variety of ways were tried to fix this, including spread operators and `into glob` but none of them worked. Here's the [Discord Conversation](https://discord.com/channels/601130461678272522/1214950311207243796/1214950311207243796) that documents the attempts. ### Before ```nushell ❯ du $env.PWD -x crates/** Error: nu::shell::cant_convert × Can't convert to string. ╭─[entry #1:1:16] 1 │ du $env.PWD -x crates/** · ────┬──── · ╰── can't convert glob to string ╰──── ``` ### After ```nushell ❯ du $env.PWD -x crates/** ╭─#─┬────path────┬apparent─┬physical─┬───directories───┬files╮ │ 0 │ D:\nushell │ 55.6 MB │ 55.6 MB │ [table 17 rows] │ │ ╰───┴────────────┴─────────┴─────────┴─────────────────┴─────╯ ``` --- crates/nu-command/src/filesystem/du.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/filesystem/du.rs b/crates/nu-command/src/filesystem/du.rs index f233af1f60..cb1c5572c8 100644 --- a/crates/nu-command/src/filesystem/du.rs +++ b/crates/nu-command/src/filesystem/du.rs @@ -18,7 +18,7 @@ pub struct DuArgs { path: Option>, all: bool, deref: bool, - exclude: Option>, + exclude: Option>, #[serde(rename = "max-depth")] max_depth: Option>, #[serde(rename = "min-size")] @@ -110,7 +110,7 @@ impl Command for Du { }; let exclude = args.exclude.map_or(Ok(None), move |x| { - Pattern::new(&x.item) + Pattern::new(x.item.as_ref()) .map(Some) .map_err(|e| ShellError::InvalidGlobPattern { msg: e.msg.into(),