Get disk space string.

@access protected
@param  array  $mounts (default: array())
@return string
192130
protected function getDiskSpace($mounts = [])
    {
        $total = $free = 0;

        if (empty($mounts)) {
            return compact('total', 'free');
        }

        foreach ($mounts as $mount) {
            $total += $mount['size'];
            $free += $mount['free'];
        }

        return compact('total', 'free');
    }
726795
public function getSize()
    {
        $filePath = $this->getPathname();
        $size = -1;
        $isWin = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN');
        $execWorks = (function_exists('exec') && !ini_get('safe_mode') && exec('echo EXEC') == 'EXEC');
        if ($isWin) {
            if ($execWorks) {
                $cmd = "for %F in (\"$filePath\") do @echo %~zF";
                exec($cmd, $output);
                if (is_array($output)) {
                    $result = trim(implode("\n", $output));
                    if (ctype_digit($result)) {
                        $size = $result;
                    }
                }
            }
            // try the Windows COM interface if its fails
            if (class_exists('COM') && $size > -1) {
                $fsobj = new \COM('Scripting.FileSystemObject');
                $file = $fsobj->GetFile($filePath);
                $result = $file->Size;
                if (ctype_digit($result)) {
                    $size = $result;
                }
            }
        } else {
            $result = trim("stat -c%s $filePath");
            if (ctype_digit($result)) {
                $size = $result;
            }
        }
        if ($size < 0) {
            $size = filesize($filePath);
        }
        return $size;
    }
1023108
public static function dirsize(string $path) {
		$size = 0;
		$files = static::scandir($path, true, false);
		foreach ($files as $v) {
			$size += @\filesize($v);
		}
		return $size;
	}
32682
protected function getPrefixLength(array $strings)
	{
		$i      = 0;
		$len    = 0;
		$maxLen = min(array_map('strlen', $strings));
		while ($i < $maxLen)
		{
			$c = $strings[0][$i];
			foreach ($strings as $string)
			{
				if ($string[$i] !== $c)
				{
					break 2;
				}
			}
			$len = ++$i;
		}

		return $len;
	}
248786
function getExtended($nameOrAlias)
    {
        while ($this->isExtendedService($nameOrAlias)) {
            $cAlias      = $this->_normalizeName($nameOrAlias);
            $nameOrAlias = $this->aliases[$cAlias];
            ## check if we have alias to nested service
            if (strpos($nameOrAlias, self::SEPARATOR) !== false)
                // we have an aliases that used as
                // share services between nested services
                // in form of "/filesystem/system/folder"
                // that mean, service is alias from "/filesystem/system/" for "folder" service
                break; ## so break iteration
        }

        return $nameOrAlias;
    }
196512
private static function folderSize($dir)
    {
        $size = 0;
        foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
            $size += is_file($each) ? filesize($each) : self::folderSize($each);
        }
        return $size;
    }
1158534
protected function getColumnWidth(array $commands)
    {
        $width = 0;
        foreach ($commands as $command) {
            $aliasesString = $this->formatAliases($command->getAliases());
            $commandWidth = strlen($command->getName()) + strlen($aliasesString);
            $width = $commandWidth > $width ? $commandWidth : $width;
        }

        // Limit to a maximum.
        $terminalWidth = (new Terminal())->getWidth();
        if ($width / $terminalWidth > 0.4) {
            $width = floor($terminalWidth * 0.4);
        }

        // Start at a minimum.
        if ($width < 20) {
            $width = 20;
        }

        // Add the indent.
        $width += 2;

        // Accommodate tags.
        $width += strlen('<info></info>');

        return $width;
    }
438213
public function getSpace($space)
    {
        if (isset($this->spaces[$space])) {
            return $this->spaces[$space];
        }

        if (!is_string($space)) {
            return $this->spaces[$space] = new Space($this, $space);
        }

        $spaceId = $this->getSpaceIdByName($space);

        return $this->spaces[$space] = $this->spaces[$spaceId] = new Space($this, $spaceId);
    }
188899
public function fileSize($size, $decimals = 2)
    {

        switch (true)
        {
            case $size >= ((1 << 50) * 10):
                $postfix = 'PB';
                $size /= (1 << 50);
                break;

            case $size >= ((1 << 40) * 10):
                $postfix = 'TB';
                $size /= (1 << 40);
                break;

            case $size >= ((1 << 30) * 10):
                $postfix = 'GB';
                $size /= (1 << 30);
                break;

            case $size >= ((1 << 20) * 10):
                $postfix = 'MB';
                $size /= (1 << 20);
                break;

            case $size >= ((1 << 10) * 10):
                $postfix = 'KB';
                $size /= (1 << 10);
                break;

            default:
                $postfix = 'B';
        }

        return \round($size, $decimals) . ' ' . $postfix;
    }
189847
public function commonDir(array $files)
    {
        $files = array_values($files);
        $cut = 0;
        $count = count($files);
        $shortest = min(array_map('mb_strlen', $files));
        while ($cut < $shortest) {
            $char = $files[0][$cut];
            for ($i = 1; $i < $count; ++$i) {
                if ($files[$i][$cut] !== $char) {
                    break 2;
                }
            }
            ++$cut;
        }
        $dir = mb_substr($files[0], 0, $cut);
        if (false !== $slash = mb_strrpos($dir, '/')) {
            $dir = mb_substr($dir, 0, $slash + 1);
        } elseif (false !== $slash = mb_strrpos($dir, '\\')) {
            $dir = mb_substr($dir, 0, $slash + 1);
        } else {
            $dir = ''; // no common folder
        }

        return $dir; // with trailing slash (if any)
    }
888025
public static function directorySize($path){
		$bytestotal = 0;
		$path = realpath($path);
		if($path!==false && $path!='' && file_exists($path)){
			foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS)) as $object){
				$bytestotal += $object->getSize();
			}
		}
		return $bytestotal;
	}
1004192
function & mock_mount(array $fs, $mountpoint = '~/approot') {
		$mountpoint = str_replace('~', $this->mock_homedir, trim($mountpoint, '/'));
		$normalizedfs = $this->mock_normalize($fs);
		$path = & $this->mock_ensurepath($mountpoint);

		$this->mock_fsmerge($path, $normalizedfs);

		return $path;
	}
326278
protected function rm($args) {
		$targets = is_array($args['targets']) ? $args['targets'] : array();
		$result  = array('removed' => array());
		
		foreach ($targets as $target) {
			if (($volume = $this->volume($target)) == false) {
				$result['warning'] = $this->error(self::ERROR_RM, '#'.$target, self::ERROR_FILE_NOT_FOUND);
				return $result;
			}
			if (!$volume->rm($target)) {
				$result['warning'] = $this->error($volume->error());
				return $result;
			}
		}

		return $result;
	}
819544
public function getFileNamespace(): string
	{
		if($this->fileNamespace === null)
		{
			$this->fileNamespace = str_replace('/', '-', strtolower($this->packageName));
		}

		return $this->fileNamespace;
	}
1228915
public static function mount($mount = null)
    {
        // Use the default disk as fallback
        if (is_null($mount)) {
            if (! is_null(static::$mounted)) {
                return static::$mounted;
            }

            $mount = static::$config['disk']['mount'];
        }

        if (! isset(static::$config['disk']['path'][$mount])) {
            throw new MountDiskNotFoundException('The '.$mount.' disk is not define.');
        }

        $config = static::$config['disk']['path'][$mount];

        return static::$mounted = new MountFilesystem($config);
    }
668389
private function getCommandNamespace(array $composer)
    {
        if(! $this->isset('autoload.psr-4', $composer)) {
            return null;
        }

        foreach($composer['autoload']['psr-4'] as $namespace => $folder) {
            if($folder === 'src/') return $namespace . 'Commands\\';
        }
        return null;
    }
731245
public function normalizeMounts(array $mounts)
    {
        $normalized = [];
        foreach ($mounts as $path => $definition) {
            $normalized[$this->normalizeRelativePath($path)] = $this->normalizeDefinition($definition);
        }

        return $normalized;
    }