]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/image/download/download.factor
io.files: exists? -> file-exists? and rename primitive.
[factor.git] / basis / bootstrap / image / download / download.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs bootstrap.image checksums checksums.md5
4 http.client io.files kernel math.parser splitting urls ;
5 IN: bootstrap.image.download
6
7 CONSTANT: url URL" http://downloads.factorcode.org/images/master/"
8
9 : download-checksums ( -- alist )
10     url "checksums.txt" >url derive-url http-get nip
11     lines [ " " split1 ] { } map>assoc ;
12
13 : file-checksum ( image -- checksum )
14     md5 checksum-file bytes>hex-string ;
15
16 : download-checksum ( image -- checksum )
17     download-checksums at ;
18
19 : need-new-image? ( image -- ? )
20     dup file-exists?
21     [ [ file-checksum ] [ download-checksum ] bi = not ]
22     [ drop t ]
23     if ;
24
25 : verify-image ( image -- )
26     need-new-image? [ "Boot image corrupt" throw ] when ;
27
28 : download-image ( image -- )
29     [ url swap >url derive-url download ]
30     [ verify-image ]
31     bi ;
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