summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorGiacomo Leidi <goodoldpaul@autistici.org>2020-05-12 23:31:30 +0200
committerGuix Patches Tester <>2020-05-12 22:34:09 +0100
commitb4d68d22aad1ed255a113a7294b278c9d3f63d34 (patch)
tree7e42753f426e9d9420a49d051c36ec67b33487a6 /guix
parenta1891cbffb9909d4a74faf242f28f0f2e998eb2f (diff)
downloadguix-patches-b4d68d22aad1ed255a113a7294b278c9d3f63d34.tar
guix-patches-b4d68d22aad1ed255a113a7294b278c9d3f63d34.tar.gz
guix: Add globstar support.
* guix/glob.scm (string->sglob) (glob-match?): Add globstar support. * tests/glob.scm: Update accordingly.
Diffstat (limited to 'guix')
-rw-r--r--guix/glob.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/guix/glob.scm b/guix/glob.scm
index a9fc744802..d73783cd30 100644
--- a/guix/glob.scm
+++ b/guix/glob.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2020 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -61,6 +62,11 @@ STR, a glob pattern such as \"foo*\" or \"foo??bar\"."
(flatten (reverse (if (null? pending)
result
(cons-string pending result)))))
+ ((#\* #\* #\/ . rest)
+ (if (zero? brackets)
+ (loop rest '() 0
+ (cons* '**/ (cons-string pending result)))
+ (loop rest (cons '**/ pending) brackets result)))
(((and chr (or #\? #\*)) . rest)
(let ((wildcard (match chr
(#\? '?)
@@ -121,6 +127,15 @@ STR, a glob pattern such as \"foo*\" or \"foo??bar\"."
(string-null? str))
(('*)
#t)
+ (('**/)
+ #t)
+ (('**/ suffix . rest)
+ (let ((rest (if (eq? '* suffix) (cdr rest) rest))
+ (suffix (if (eq? '* suffix) (car rest) suffix)))
+ (match (string-contains str suffix)
+ (#f #f)
+ (index (loop rest (string-drop str
+ (+ index (string-length suffix))))))))
(('* suffix . rest)
(match (string-contains str suffix)
(#f #f)