]> gitweb.factorcode.org Git - factor.git/blob - extra/mason/disk/disk.factor
816ee3ea68fffbf86efcd9d9e147305458a9741a
[factor.git] / extra / mason / disk / disk.factor
1 ! Copyright (C) 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors io.files.info io.pathnames kernel mason.config
4 math math.parser namespaces sequences ;
5 IN: mason.disk
6
7 : gb ( -- n ) 30 2^ ; inline
8
9 : sufficient-disk-space? ( -- ? )
10     ! We want at least 300Mb to be available before starting
11     ! a build.
12     current-directory get file-system-info available-space>>
13     gb > ;
14
15 : check-disk-space ( -- )
16     sufficient-disk-space? [
17         "Less than 1 Gb free disk space." throw
18     ] unless ;
19
20 : mb-str ( n -- string ) gb /i number>string ;
21
22 : disk-usage ( -- string )
23     builds-dir get file-system-info
24     [ used-space>> ] [ total-space>> ] bi
25     [ [ mb-str ] bi@ " / " glue " Gb used" append ]
26     [ [ 100 * ] dip /i number>string "(" "%)" surround ] 2bi
27     " " glue ;