2020-01-03 11:48:24 -05:00
|
|
|
! Copyright (C) 2010 Slava Pestov, Doug Coleman.
|
2010-09-05 18:22:02 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2020-01-03 11:48:24 -05:00
|
|
|
USING: accessors formatting io.files.info io.pathnames kernel
|
|
|
|
mason.config math namespaces ;
|
2010-09-05 18:22:02 -04:00
|
|
|
IN: mason.disk
|
|
|
|
|
2020-01-03 11:48:24 -05:00
|
|
|
: Gi ( n -- gibibits ) 30 2^ * ; inline
|
2010-09-05 18:22:02 -04:00
|
|
|
|
|
|
|
: sufficient-disk-space? ( -- ? )
|
2020-01-04 14:40:26 -05:00
|
|
|
current-directory get find-mount-point
|
|
|
|
file-system-info available-space>> 1 Gi > ;
|
2010-09-05 18:22:02 -04:00
|
|
|
|
|
|
|
: check-disk-space ( -- )
|
|
|
|
sufficient-disk-space? [
|
2020-01-03 11:48:24 -05:00
|
|
|
"Less than 1 Gi free disk space." throw
|
2010-09-05 18:22:02 -04:00
|
|
|
] unless ;
|
|
|
|
|
2020-01-03 11:48:24 -05:00
|
|
|
: Gi-str ( n -- string ) 1 Gi /f ;
|
|
|
|
|
|
|
|
: path>disk-usage ( path -- string )
|
2020-01-04 14:40:26 -05:00
|
|
|
find-mount-point file-system-info
|
2020-01-03 11:48:24 -05:00
|
|
|
[ used-space>> ] [ available-space>> ] [ total-space>> ] tri
|
|
|
|
2dup /f 100 *
|
|
|
|
[ [ Gi-str ] tri@ ] dip
|
|
|
|
"%0.2fGi used, %0.2fGi avail, %0.2fGi total, %0.2f%% free" sprintf ;
|
2010-09-05 18:22:02 -04:00
|
|
|
|
|
|
|
: disk-usage ( -- string )
|
2020-01-03 16:18:14 -05:00
|
|
|
builds-dir get path>disk-usage ;
|