Commit graph

21 commits

Author SHA1 Message Date
Daniel Hofstetter
bf69c63e09 df: Fix calculation of Use% in "total" row
Change formula from: "Used/Size * 100" to "Used/(Used + Avail) * 100".
This formula also works if "Used" and "Avail" do not add up to "Size",
which is the case if there are reserved disk blocks.
2022-04-01 08:25:30 +02:00
Sylvestre Ledru
05ec34eb94
Merge pull request #3322 from jfinkels/df-multiple-columns-error
df: error on duplicate columns in --output arg
2022-03-29 22:30:14 +02:00
Daniel Hofstetter
e152ebaead df: fix calculation of Use% column
Change formula from: "Used/Size * 100" to "Used/(Used + Avail) * 100".
This formula also works if "Used" and "Avail" do not add up to "Size",
which is the case if there are reserved disk blocks.
2022-03-28 18:57:12 +02:00
Daniel Hofstetter
a68d77b8cf df: --output w/o "=" doesn't expect further args
"df --output ." was treated as "df --output=." and hence "." was
interpreted as a column name. With this commit, "." is treated as
an argument on its own.

Fixes #3324
2022-03-28 10:13:54 +02:00
Jeffrey Finkelstein
a1f300e8a7 df: allow multiple occurrences of --output arg
Allow multiple occurrences of the `--output` argument. For example,

    $ df --output=source --output=target | head -n1
    Filesystem                Mounted on
2022-03-27 22:14:16 -04:00
Jeffrey Finkelstein
6f32a1921a df: error on duplicate columns in --output arg
Print a usage error when duplicat column names are specified to the
`--output` command-line argument. For example,

    $ df --output=source,source
    df: option --output: field ‘source’ used more than once
    Try 'df --help' for more information.
2022-03-27 22:02:55 -04:00
Jeffrey Finkelstein
ab717ce370 df: implement the File column
Implement the "File" column in the `df` output table. Before this
commit, a blank entry appeared in the "File" column for each
row. After this commit, a "-" entry appears when `df` is run with no
positional arguments and the filename appears when run with positional
arguments. For example:

    $ touch a b c && df --output=target,file a b c
    Mounted on File
    /          a
    /          b
    /          c
2022-03-27 13:17:36 -04:00
Daniel Hofstetter
433504949d df: fix panic when using -x argument (#3257)
Also allow multiple '-x' options
2022-03-14 10:32:42 +01:00
Kartik Sharma
5c5f4ca6ad
df: Adds support for mount path prefix matching and input path (#3161)
* Adds support for mount path prefix matching and input path
canonicalization

- Sorts mount paths in reverse lexicographical order
- Canonicalize all paths and clear invalid paths
- Checking of mount path prefix matches input path
2022-03-11 09:36:34 +01:00
Jeffrey Finkelstein
c0cd017706 tests: update test_df.rs to use --output argument 2022-03-10 22:50:15 -05:00
Jeffrey Finkelstein
ec048b3857 df: implement the --output command-line argument
Implement the `--output` command-line argument, which allows
specifying an exact sequence of columns to display in the output
table. For example,

    $ df --output=source,fstype | head -n3
    Filesystem       Type
    udev             devtmpfs
    tmpfs            tmpfs

(The spacing does not exactly match the spacing of GNU `df` yet.)

Fixes #3057.
2022-03-10 22:50:15 -05:00
Daniel Hofstetter
3317fb9924 df: always round up usage percentage (#3208) 2022-03-08 15:13:05 +01:00
Jeffrey Finkelstein
5cf7139467 df: fix block size header for multiples of 1024
Correct the column header printed by `df` when the `--block-size`
argument has a value that is a multiple of 1024. After this commit,
the header looks like "1K" or "4M" or "117G", etc., depending on the
particular value of the block size. For example:

    $ df --block-size=1024 | head -n1
    Filesystem                1K-blocks     Used Available Use% Mounted on
    $ df --block-size=2048 | head -n1
    Filesystem                2K-blocks     Used Available Use% Mounted on
    $ df --block-size=3072 | head -n1
    Filesystem                3K-blocks     Used Available Use% Mounted on
    $ df --block-size=4096 | head -n1
    Filesystem                4K-blocks     Used Available Use% Mounted on
2022-03-05 11:47:45 -05:00
Jeffrey Finkelstein
d0ebd1c9d0 df: add support for --total option
Add support for the `--total` option to `df`, which displays the total
of each numeric column. For example,

    $ df --total
    Filesystem            1K-blocks     Used Available Use% Mounted on
    udev                    3858016        0   3858016   0% /dev
    ...
    /dev/loop14               63488    63488         0 100% /snap/core20/1361
    total                 258775268 98099712 148220200  40% -
2022-03-05 10:29:46 +01:00
xxyzz
c16c06ea0d
df: add output option's valid field names 2022-02-17 13:43:59 +08:00
Jeffrey Finkelstein
b6d1aa3e73 df: always produce the same order in output table
Change the `filter_mount_list()` function so that it always produces
the same order of `MountInfo` objects. This change ultimately results
in `df` printing its table of filesystems in the same order on each
execution. Previously, the table was in an arbitrary order because the
`MountInfo` objects were read from a `HashMap`.

Fixes #3086.
2022-02-12 21:14:14 -05:00
Terts Diepraam
2412e4cbf7 add some tests for Clap's InferLongArgs setting 2022-01-29 02:06:32 +01:00
Sylvestre Ledru
a74a729aa8 rustfmt the recent change 2021-05-08 13:13:52 +02:00
David CARLIER
224c8b3f94 df output update (non inode mode) proposal specific for mac. on this platform, capacity column is also displayed. 2021-05-03 15:49:55 +01:00
Jan Scheer
646c6cacbc refactor tests (#1982) 2021-04-23 02:28:46 +02:00
Roy Ivy III
de0375f909 tests ~ reorganize tests 2020-06-01 18:30:04 -05:00
Renamed from tests/test_df.rs (Browse further)