From c4fee9e63f8cb694de86ae46bd1e2e4c692eb6f6 Mon Sep 17 00:00:00 2001 From: Chris Marusich Date: Sun, 19 Jun 2022 13:16:04 -0700 Subject: [PATCH] environment: Don't assume that lines have a trailing "\r". I've noticed that the child-shell-environment procedure is misbehaving on my computer because the lines returned by read-line do not have a trailing "\r". In the past, I recall that such lines did in fact have a trailing "\r". I'm not sure why it changed, but it seems prudent to just rewrite this code to tolerate both cases, since it seems that both cases can happen. * guix/scripts/environment.scm (child-shell-environment) [lines]: Instead of checking if the line exactly matches "GUIX_CHECK_DONE\r"; check if the line begins with "GUIX_CHECK_DONE". Instead of always stripping the trailing character from the line, only do it if the line has a trailing "\r". --- guix/scripts/environment.scm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index f0cb341aab..1fb4f5b7c6 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -462,13 +462,18 @@ (define lines ;; prompt from getting mixed into what we read. (match (read-line shell-pipe-in) ((? eof-object?) (reverse lines)) - ("GUIX-CHECK-DONE\r" + ((? (lambda (line) + ;; The line might or might not have a trailing \r. + (string-prefix? "GUIX-CHECK-DONE" line))) (display "done\n" port) (reverse lines)) (line - ;; Drop the '\r' from LINE. - (loop (cons (string-drop-right line 1) - lines)))))))) + ;; Strip the trailing '\r' from LINE if present. + (let ((stripped-line + (if (string-suffix? "\r" line) + (string-drop-right line 1) + line))) + (loop (cons stripped-line lines))))))))) (close-port port) (close-port shell-pipe-in) (waitpid pid) -- 2.34.0