aboutsummaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-05-13 15:24:38 +0200
committerLudovic Courtès <ludo@gnu.org>2017-05-13 16:52:11 +0200
commitc7d1b061f5e3fb33085e8dc06431517da5f4abfb (patch)
tree024c77e7da54ad24d2010d94d63277618da48ec2 /guix/build
parent0e40b75506bf189d44d633fae5d3fe2cc13d62f6 (diff)
downloadgnu-guix-c7d1b061f5e3fb33085e8dc06431517da5f4abfb.tar
gnu-guix-c7d1b061f5e3fb33085e8dc06431517da5f4abfb.tar.gz
bournish: 'ls' lists directory contents.
Suggested by Ricardo Wurmus. * guix/build/bournish.scm (ls-command-implementation): When FILE is a directory, list its contents rather than FILE itself.
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/bournish.scm36
1 files changed, 25 insertions, 11 deletions
diff --git a/guix/build/bournish.scm b/guix/build/bournish.scm
index e948cd03d3..7aa1f8ca00 100644
--- a/guix/build/bournish.scm
+++ b/guix/build/bournish.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
;;;
@@ -81,16 +81,30 @@ characters."
(()
(display-tabulated (scandir ".")))
(files
- (let ((files (filter (lambda (file)
- (catch 'system-error
- (lambda ()
- (lstat file))
- (lambda args
- (let ((errno (system-error-errno args)))
- (format (current-error-port) "~a: ~a~%"
- file (strerror errno))
- #f))))
- files)))
+ (let ((files (append-map (lambda (file)
+ (catch 'system-error
+ (lambda ()
+ (match (stat:type (lstat file))
+ ('directory
+ ;; Like GNU ls, list the contents of
+ ;; FILE rather than FILE itself.
+ (match (scandir file
+ (match-lambda
+ ((or "." "..") #f)
+ (_ #t)))
+ (#f
+ (list file))
+ ((files ...)
+ (map (cut string-append file "/" <>)
+ files))))
+ (_
+ (list file))))
+ (lambda args
+ (let ((errno (system-error-errno args)))
+ (format (current-error-port) "~a: ~a~%"
+ file (strerror errno))
+ '()))))
+ files)))
(display-tabulated files)))))
(define (ls-command . files)