#3658 PR open: Use extglob instead of brace expansion in FILES_TO_PATCH_PATTERNS

Labels: enhancement, minor bug, ready-to-merge?

svlv opened issue at 2026-10-29 11:23:

  • Type: Bug Fix

  • Impact: Normal

  • Reference to related issue (URL):

  • How was this pull request tested?
    Verified that files.md5sum contains hash for /boot/grub2/grub.cfg

  • Description of the changes in this pull request:

    Bash does not perform brace expansion on variable values, so the {...} lists in FILES_TO_PATCH_PATTERNS were passed to pathname expansion literally, matched nothing, and were dropped by nullglob. As a result the GRUB files (grub.conf, grub.cfg, menu.lst, device.map) were excluded from checksum generation and from UUID and device name migration. The bug introduced by 7f61a4f4283e403ba3e44db9ee6bd52bd45d9519.

    Reproduce in a terminal:

    $ mkdir -p boot/grub2
    $ touch boot/grub2/grub.cnf
    $ shopt -s nullglob
    
    $ for file in [b]oot/grub2/{grub.cnf,grub.conf} ; do echo "$file" ; done
    boot/grub2/grub.cnf <=== expected output, since boot/grub2/grub.cnf exists
    
    $ GLOB="[b]oot/grub2/{grub.cnf,grub.conf}" ; for file in $GLOB ; do echo "$file" ; done
                      <=== nothing, which is unexpected and indicates the issue
    

    Replace brace expansion in FILE_TO_PATCH_PATTERNS with Bash extended globbing, which is implicitly enabled in ReaR.

codacy-production commented at 2026-10-29 11:25:

Up to standards ✅

🟢 Issues 0 issues >
> > **Results:** > `0` new issues > > [View in > Codacy](https://app.codacy.com/gh/rear/rear/pull-requests/3658/issues) >

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

pcahyna commented at 2026-10-30 10:42:

The bug introduced by https://github.com/rear/rear/commit/7f61a4f4283e403ba3e44db9ee6bd52bd45d9519.

Oops :-( thank you for spotting it. Will have a look.

jsmeix commented at 2026-11-02 14:55:

It works
(at least for me with GNU bash, version 5.2.37)
but I fail to understand why.

When reading "man bash" which reads

    @(pattern-list)
        Matches one of the given patterns

I falsely thought that e.g.

@(grub.conf|grub.cfg|grubenv|menu.lst|device.map)

would match only one of the listed patterns.

But actually it matches all that exist:

# ls /boot/grub2
fonts  grub.cfg  grubenv  locale  themes  x86_64-efi

# ( shopt -s nullglob extglob ; \
  for f in /[b]oot/grub2/{grub.conf,grub.cfg,grubenv,menu.lst,device.map} ; \
  do echo "$f" ; done )
/boot/grub2/grub.cfg
/boot/grub2/grubenv

# ( shopt -s nullglob extglob ; \
  g="/[b]oot/grub2/{grub.conf,grub.cfg,grubenv,menu.lst,device.map}" ; \
  for f in $g ; do echo "$f" ; done )

# ( shopt -s nullglob extglob ; \
  g="/[b]oot/grub2/@(grub.conf|grub.cfg|grubenv|menu.lst|device.map)" ; \
  for f in $g ; do echo "$f" ; done )
/boot/grub2/grub.cfg
/boot/grub2/grubenv

Can one explain how that works?

svlv commented at 2026-11-02 15:07:

It's better to think about it keeping the following in the head:

@( … ) | Only one occurrence
*( … ) | Zero or more occurrences
+( … ) | One or more occurrences
?( … ) | Zero or one occurrences
!( … ) | Not these occurrences, but anything else

@(a|b).jpeg will match a.jpeg or b.jpeg but not aa.jpeg or bb.jpeg. I think this short explanation will be enough

gdha commented at 2026-11-05 13:30:

@rear/contributors if there are no objection would like to merge this PR around Nov.11th


[Export of Github issue for rear/rear.]