|
16 | 16 | "Fetch URL and safe it to FILE." |
17 | 17 | (declare (ignorable args)) |
18 | 18 | (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)) |
23 | 25 | (restart-case |
24 | 26 | (handler-bind ((error (lambda (c) |
25 | 27 | (declare (ignore c)) |
|
37 | 39 | (setf *quietly-use-https* t) |
38 | 40 | (apply #'fetcher url file args))))) |
39 | 41 |
|
| 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)))) |
40 | 66 |
|
41 | 67 | (defun register-fetch-scheme-functions () |
42 | 68 | (setf ql-http:*fetch-scheme-functions* |
|
0 commit comments