public static function createDir(
        string $prefix = "tmp",
        int $mode = 0777,
        int $maxAttempts = 10
    ): entity\DirEntity
    {
        $tmpdir = static::getDir();
        $prefix = \sndsgd\Fs::sanitizeName($prefix);
        $attempts = 0;
        do {
            $attempts++;
            if ($attempts > $maxAttempts) {
                throw new \RuntimeException(
                    "failed to create temp directory; ".
                    "reached max number ($maxAttempts) of attempts"
                );
            }
            $rand = \sndsgd\Str::random(10);
            $path = "$tmpdir/$prefix-$rand";
        }
        while (@mkdir($path, $mode) === false);

        $dir = new entity\DirEntity($path);
        static::registerEntity($dir);
        return $dir;
    }