# All files / src/platforms linux.ts

100% Statements 17/17
100% Branches 8/8
100% Functions 3/3
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    461x

    1x
    1x

    1x

    1x

    4x
    4x
    4x

    4x

    52x

    48x
    48x

    48x

    48x

    4x

    1x
     import {Constants} from '../utils/constants';

    import Drive from '../classes/drive';
    import {Utils} from "../utils/utils";

    /**
     * Class with Linux specific logic to get disk info.
     */
    export class Linux {

        /**
         * Execute specific Linux command to get disk info.
         *
         * @return {Drive[]} List of drives and their info.
         */
        public static run(): Drive[] {

            const drives: Drive[] = [];
            const buffer = Utils.execute(Constants.LINUX_COMMAND);
            const lines = buffer.toString().split('\n');

            lines.forEach((value) => {

                if (value !== '') {

                    const line: string = value.replace(/ +(?= )/g, '');
                    const tokens = line.split(' ');

                    const d = new Drive(
                        tokens[0],
                        isNaN(parseFloat(tokens[1])) ? 0 : +tokens[1],
                        isNaN(parseFloat(tokens[2])) ? 0 : +tokens[2],
                        isNaN(parseFloat(tokens[3])) ? 0 : +tokens[3],
                        tokens[4],
                        tokens[5]);

                    drives.push(d);
                }

            });

            return drives;
        }

    }