|
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 | + (release (url-to-release url))) |
| 24 | + (when release |
| 25 | + (verify-download file release)) |
| 26 | + (values output file)) |
23 | 27 | (restart-case |
24 | 28 | (handler-bind ((error (lambda (c) |
25 | 29 | (declare (ignore c)) |
|
37 | 41 | (setf *quietly-use-https* t) |
38 | 42 | (apply #'fetcher url file args))))) |
39 | 43 |
|
| 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)))) |
40 | 69 |
|
41 | 70 | (defun register-fetch-scheme-functions () |
42 | 71 | (setf ql-http:*fetch-scheme-functions* |
|
0 commit comments