40 lines
1.1 KiB
Scheme
40 lines
1.1 KiB
Scheme
(define-module (ordo condition)
|
|
#:use-module (srfi srfi-71)
|
|
#:use-module (ordo connection)
|
|
#:use-module (ordo interceptor)
|
|
#:use-module (ordo action filesystem))
|
|
|
|
(define-public (cond:any preds)
|
|
(lambda (ctx)
|
|
(let loop ((preds preds))
|
|
(if (null? preds)
|
|
#f
|
|
(let ((p (car preds)))
|
|
(if (p ctx)
|
|
#t
|
|
(loop (cdr preds))))))))
|
|
|
|
(define-public (cond:every preds)
|
|
(lambda (ctx)
|
|
(let loop ((preds preds))
|
|
(if (null? preds)
|
|
#t
|
|
(let ((p (car preds)))
|
|
(if (p ctx)
|
|
(loop (cdr preds))
|
|
#f))))))
|
|
|
|
(define-public (cond:command-available? cmd-name)
|
|
(lambda (ctx)
|
|
(let ((_ rc (run (context-connection ctx) "which" cmd-name)))
|
|
(zero? rc))))
|
|
|
|
(define-public (cond:directory? path)
|
|
(lambda (ctx)
|
|
(let ((st (fs:stat (context-connection ctx) path)))
|
|
(and st (string=? "directory" (assoc-ref st 'file-type))))))
|
|
|
|
(define-public (cond:regular-file? path)
|
|
(lambda (ctx)
|
|
(let ((st (fs:stat (context-connection ctx) path)))
|
|
(and st (string=? "regular-file" (assoc-ref st 'file-type))))))
|