// Copyright F3 Authors
// SPDX-License-Identifier: MIT

package util

import (
	"fmt"
	"io/fs"
	"os"
)

func FileExists(pathname string) bool {
	_, err := os.Stat(pathname)
	if err == nil {
		return true
	}
	if os.IsNotExist(err) {
		return false
	}
	panic(fmt.Errorf("Stat(%s): ", pathname))
}

func IsDir(dir string) bool {
	f, err := os.Stat(dir)
	if err == nil {
		return f.IsDir()
	}
	if os.IsNotExist(err) {
		return false
	}
	panic(fmt.Errorf("Stat(%s): ", dir))
}

func ReadDir(pathname string) []fs.DirEntry {
	entries, err := os.ReadDir(pathname)
	if err != nil {
		panic(fmt.Errorf("ReadDir(%s): %w", pathname, err))
	}
	return entries
}
