From b7952cf8eb987cdee5631efc7b39d6af4feae879 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 7 Dec 2024 21:46:43 -0500 Subject: [PATCH] providers/os: Add functions to check if something is a dir or file --- providers/os/os.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/providers/os/os.go b/providers/os/os.go index 859a421..7ef5849 100644 --- a/providers/os/os.go +++ b/providers/os/os.go @@ -29,6 +29,8 @@ func (this *Provider) FuncMap () template.FuncMap { return template.FuncMap { "env": funcEnv, "fileExists": funcFileExists, + "isFile": funcIsFile, + "isDir": funcIsDir, "statFile": funcStatFile, "readFile": funcReadFile, "readDir": funcReadDir, @@ -47,6 +49,18 @@ func funcFileExists (name string) (bool) { return err == nil } +func funcIsFile (name string) (bool, error) { + info, err := os.Stat(name) + if err != nil { return false, err } + return info.Mode().IsRegular(), nil +} + +func funcIsDir (name string) (bool, error) { + info, err := os.Stat(name) + if err != nil { return false, err } + return info.IsDir(), nil +} + func funcStatFile (name string) (FileInfo, error) { info, err := os.Stat(name) if err != nil { return FileInfo { }, err }