| 1 |
;; Run glob on remote machine |
| 2 |
;; |
| 3 |
;; It shows how to customize glob. |
| 4 |
;; This isn't a best way to implement remote glob, though, for it needs |
| 5 |
;; to call remote process on every path component. |
| 6 |
|
| 7 |
(use gauche.process) |
| 8 |
(use file.util :only (build-path)) |
| 9 |
(use srfi.13 :only (string-trim-right string-drop-right)) |
| 10 |
|
| 11 |
(define (make-remote-folder host) |
| 12 |
(^[proc seed parent regexp non-leaf?] |
| 13 |
(let1 prefix (case parent |
| 14 |
[(#t) "/"] |
| 15 |
[(#f) "./"] |
| 16 |
[else (string-append (string-trim-right parent #\/))]) |
| 17 |
(cond [(eq? regexp 'dir) ; returns the directory itself |
| 18 |
(proc prefix seed)] |
| 19 |
[non-leaf? |
| 20 |
($ fold proc seed |
| 21 |
$ filter-map (^p (and (regexp p) (build-path prefix p))) |
| 22 |
$ filter-map (^p (and (#/\/$/ p) (string-drop-right p 1))) |
| 23 |
$ process-output->string-list `(ls -F ,prefix) :host host)] |
| 24 |
[else |
| 25 |
($ fold proc seed |
| 26 |
$ filter-map (^p (and (regexp p) (build-path prefix p))) |
| 27 |
$ process-output->string-list `(ls ,prefix) :host host)])))) |
| 28 |
|
| 29 |
(define (remote-glob host pattern) |
| 30 |
(glob pattern :folder (make-remote-folder host))) |