Skip to content

Commit 34d1b0b

Browse files
committed
check md5 and length of downloads
1 parent 5dae25e commit 34d1b0b

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

ql-https.lisp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
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+
(verify-download file (url-to-release url))
24+
(values output file))
2325
(restart-case
2426
(handler-bind ((error (lambda (c)
2527
(declare (ignore c))
@@ -37,6 +39,30 @@
3739
(setf *quietly-use-https* t)
3840
(apply #'fetcher url file args)))))
3941

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

4167
(defun register-fetch-scheme-functions ()
4268
(setf ql-http:*fetch-scheme-functions*

0 commit comments

Comments
 (0)