Skip to content

Commit 355d0e2

Browse files
authored
Merge branch 'rudolfochrist:master' into install-script
2 parents 99741ea + 8a2f999 commit 355d0e2

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

ql-https.lisp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
"Fetch URL and safe it to FILE."
1717
(declare (ignorable args))
1818
(if (uiop:string-prefix-p "https://" url)
19-
(values (uiop:run-program (format nil "curl -fsSL ~A -o ~A" url file)
20-
:output '(:string :stripped t)
21-
:error-output :output)
22-
(and file (probe-file file)))
19+
(let ((output (uiop:run-program (format nil "curl -fsSL ~A -o ~A" url file)
20+
:output '(:string :stripped t)
21+
:error-output :output))
22+
(file (and file (probe-file file)))
23+
(release (url-to-release url)))
24+
(when release
25+
(verify-download file release))
26+
(values output file))
2327
(restart-case
2428
(handler-bind ((error (lambda (c)
2529
(declare (ignore c))
@@ -37,6 +41,31 @@
3741
(setf *quietly-use-https* t)
3842
(apply #'fetcher url file args)))))
3943

44+
(defun url-to-release (url)
45+
"extracts name of release from URL"
46+
(when (search "/archive/" url)
47+
(let* ((start (+ (search "/archive/" url) (length "/archive/")))
48+
(end (position #\/ url :start start)))
49+
(subseq url start end))))
50+
51+
(defun md5 (file)
52+
"Returns md5sum of FILE"
53+
(uiop:run-program (format nil "md5sum \"~A\" | cut -d' ' -f 1" file)
54+
:output '(:string :stripped t)))
55+
56+
(defun file-size (file)
57+
"Returns the size of FILE in bytes"
58+
(with-open-file (f file)
59+
(file-length f)))
60+
61+
(defun verify-download (file name)
62+
"Checks that the md5 and size of FILE are as expected from the quicklisp
63+
dist."
64+
(let ((release (ql-dist:find-release name)))
65+
(unless (string= (ql-dist:archive-md5 release) (md5 file))
66+
(error "md5 mismatch for ~A" name))
67+
(unless (= (ql-dist:archive-size release) (file-size file))
68+
(error "file size mismatch for ~A" name))))
4069

4170
(defun register-fetch-scheme-functions ()
4271
(setf ql-http:*fetch-scheme-functions*

0 commit comments

Comments
 (0)