aboutsummaryrefslogtreecommitdiff
path: root/src/property/file.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-07-10 16:12:44 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-07-10 21:46:00 -0700
commitb3e8205199655d333d1bb18757b5b59510b3f8d0 (patch)
tree63bab732b0f24ad18e32ab80443f3a757429bcaf /src/property/file.lisp
parent4cfd98698d1e8e670e2824e53574903f61ad82bc (diff)
downloadconsfigurator-b3e8205199655d333d1bb18757b5b59510b3f8d0.tar.gz
FILE:UPDATE-UNIX-TABLE end sort: handle comments and blank lines
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/file.lisp')
-rw-r--r--src/property/file.lisp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/property/file.lisp b/src/property/file.lisp
index 2a3921f..2f88160 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -528,10 +528,19 @@ NO-SOURCE or \"PLACEHOLDER\", use the existing field value."
;; beginning with '/' so that all filesystems are available
;; before trying to mount to virtual targets like "swap".
;; (STRING< already sorts like this but be explicit about it.)
+ ;;
+ ;; Treat comments and blank lines as equal to any other line
+ ;; and use STABLE-SORT to try to keep comments close to lines
+ ;; they describe.
(return
- (sort (nconc accum (hash-table-values pending))
- (lambda (a b)
- (or (and (char= #\/ (first-char a))
- (not (char= #\/ (first-char b))))
- (string< a b)))
- :key (compose (curry #'nth target) #'words))))))))
+ (stable-sort
+ (nconc accum (hash-table-values pending))
+ (lambda (a b)
+ (and (plusp (length a)) (plusp (length b))
+ (not (char= #\# (first-char a)))
+ (not (char= #\# (first-char b)))
+ (let ((a* (nth target (words a)))
+ (b* (nth target (words b))))
+ (or (and (char= #\/ (first-char a*))
+ (not (char= #\/ (first-char b*))))
+ (string< a* b*))))))))))))