]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/image/download/download.factor
factor: update download to return path and using lists
[factor.git] / basis / bootstrap / image / download / download.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: assocs bootstrap.image checksums checksums.md5
4 http.client http.download io.files kernel math.parser splitting
5 urls ;
6 IN: bootstrap.image.download
7
8 CONSTANT: download-url URL" https://downloads.factorcode.org/images/master/"
9
10 : download-checksums ( -- alist )
11     download-url "checksums.txt" >url derive-url http-get nip
12     split-lines [ " " split1 ] { } map>assoc ;
13
14 : file-checksum ( image -- checksum )
15     md5 checksum-file bytes>hex-string ;
16
17 : download-checksum ( image -- checksum )
18     download-checksums at " " split1 drop ;
19
20 : need-new-image? ( image -- ? )
21     dup file-exists?
22     [ [ file-checksum ] [ download-checksum ] bi = not ]
23     [ drop t ]
24     if ;
25
26 : verify-image ( image -- )
27     need-new-image? [ "Boot image corrupt" throw ] when ;
28
29 : download-image ( image -- )
30     [ download-url ] dip >url derive-url
31     download verify-image ;
32
33 : maybe-download-image ( image -- ? )
34     dup need-new-image? [ download-image t ] [ drop f ] if ;
35
36 : download-my-image ( -- )
37     my-boot-image-name maybe-download-image drop ;
38
39 MAIN: download-my-image