Purpose:
- Save a program that writes data to disk from vain attempts of writing to a full filesystem;
- Save bandwidth (don't download if nowhere to store);
- Save user's and programmer's time and nerves (notify them of the problem instead of having them tearing out their hair with reading misleading error messages and "why the heck this software is not working!").
The question comes in 2 parts:
- Reporting storage space statistics (available, used, total etc.), either of all filesystems or of the filesystem that path in question belongs to.
- Reporting a filesystem error on running out of space.
Part 1
Share please NATIVE Raku alternative(s) (TIMTOWTDIBSCINABTE "Tim Toady Bicarbonate") to:
raku -e 'qqx{ df -P $*CWD }.print'
Here, raku
-e
xecutes df
(disk free) external program via shell quoting with interpolation qqx{}
, feeding -P
ortable-format argument and $*CWD
Current Working Directory, then .print
s the df
's output.
The snippet initially had been written as raku -e 'qqx{ df -hP $*CWD }.print'
— with both -h
uman-readable and -P
ortable — but it turned out that it is not a ubiquitously valid command. In OpenBSD 7.0, it exits with an error: df: -h and -i are incompatible with -P
.
For adding human-readability, you may consider Number::Bytes::Human module