]> gitweb.factorcode.org Git - factor.git/blob - extra/mason/disk/disk.factor
Switch to https urls
[factor.git] / extra / mason / disk / disk.factor
1 ! Copyright (C) 2010 Slava Pestov, Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors formatting io.files.info io.pathnames kernel
4 mason.config math namespaces ;
5 IN: mason.disk
6
7 : Gi ( n -- gibibits ) 30 2^ * ; inline
8
9 : sufficient-disk-space? ( -- ? )
10     current-directory get find-mount-point mount-point>>
11     file-system-info available-space>> 1 Gi > ;
12
13 : check-disk-space ( -- )
14     sufficient-disk-space? [
15         "Less than 1 Gi free disk space." throw
16     ] unless ;
17
18 : Gi-str ( n -- string ) 1 Gi /f ;
19
20 : path>disk-usage ( path -- string )
21     find-mount-point mount-point>> file-system-info
22     [ used-space>> ] [ available-space>> ] [ total-space>> ] tri
23     2dup /f 100 *
24     [ [ Gi-str ] tri@ ] dip
25     "%0.2fGi used, %0.2fGi avail, %0.2fGi total, %0.2f%% free" sprintf ;
26
27 : disk-usage ( -- string )
28     builds-dir get path>disk-usage ;