Paste number 358456: Ports get closed with dynamic-wind

Paste number 358456: Ports get closed with dynamic-wind
Pasted by: Apteryx
When:4 years, 1 month ago
Share:Tweet this! | http://paste.lisp.org/+7OL4
Channel:None
Paste contents:
Raw Source | XML | Display As
(define* (download-archive uri #:optional into-file)
  "Download URI and return its nix-base32 sha256 hash.
If the optional INTO-FILE argument is given, the archive is saved to
that file.  Return #f in case the archive could not be downloaded."
  (let ((stdout (open-output-string))
	(stderr (open-output-string)))
    (pk stdout)
    (pk stderr)
    ((dynamic-wind
	(lambda () #f)			;no in-guard thunk
	(lambda ()			;dynamic-wind thunk
	  (catch 'quit
	    (lambda ()
	      (parameterize
		  ((current-output-port stdout)
		   (current-error-port stderr))
		(lambda ()
		  (pk stdout)
		  (pk stderr)
		  (if into-file
		      (guix-download (string-append "--output=" into-file) uri)
		      (guix-download uri))
		  (let* ((output (get-output-string stdout))
			 (hash (last (string-split (string-trim-right output)
						   #\newline))))
		    ;; The nix-base32 encoded sha256 hash should be 52
		    ;; characters long.
		    (pk hash)
		    (unless (eqv? (string-length hash) 52)
		      (error "Failed to get hash from guix-download output."))
		    hash))))
	    (lambda (key . args)	;exception handler
	      (format (current-error-port) "guix-download failed: ~a~%"
		      (get-output-string stderr))
	      #f)))
	(lambda ()			;out-guard thunk
	  (close stdout)
	  (close stderr))))))

;;; Here's some output that exhibits the problem:
(download-archive "https://berlin.guixsd.org/file/libgit2-0.26.0.tar.gz/sha256/1fdk9yhwvl1w1z71ykzcvgh4nsf8scxcbclz5anh98zpplmhmisa")

;;; (#<output: file 3aa2e70>)

;;; (#<output: file 3aa2e00>)

;;; (#<closed: file 3aa2e70>)

;;; (#<closed: file 3aa2e00>)

Starting download of /tmp/guix-file.MXLiok
From https://berlin.guixsd.org/file/libgit2-0.26.0.tar.gz/sha256/1fdk9yhwvl1w1z71ykzcvgh4nsf8scxcbclz5anh98zpplmhmisa...
 …f8scxcbclz5anh98zpplmhmisa  4.5MiB                                      1.6MiB/s 00:03 [####################] 100.0%
/gnu/store/hxf2i914wy6dhwgyv39k0c9bwl5m66ak-1fdk9yhwvl1w1z71ykzcvgh4nsf8scxcbclz5anh98zpplmhmisa
1fdk9yhwvl1w1z71ykzcvgh4nsf8scxcbclz5anh98zpplmhmisa
ERROR: In procedure get-output-string:
ERROR: In procedure get-output-string: Wrong type argument in position 1 (expecting open output string port): #<closed: string 3aa2e70>

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
In current input:
  3013:33  1 (_)
In unknown file:
           0 (get-output-string #<closed: string 3aa2e70>)

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.