Add util package

This commit is contained in:
2023-05-12 15:09:39 +02:00
parent 35bc674b43
commit 6aea486891
5 changed files with 224 additions and 137 deletions

30
internal/util/fstat.go Normal file
View File

@@ -0,0 +1,30 @@
package util
import (
"errors"
"os"
"github.com/ClusterCockpit/cc-backend/pkg/log"
)
func CheckFileExists(filePath string) bool {
_, err := os.Stat(filePath)
return !errors.Is(err, os.ErrNotExist)
}
func GetFilesize(filePath string) int64 {
fileInfo, err := os.Stat(filePath)
if err != nil {
log.Errorf("Error on Stat %s: %v", filePath, err)
}
return fileInfo.Size()
}
func GetFilecount(path string) int {
files, err := os.ReadDir(path)
if err != nil {
log.Errorf("Error on ReadDir %s: %v", path, err)
}
return len(files)
}