From eb1f1c678ac2baa7a5157cdbeeb32c11ff2510b4 Mon Sep 17 00:00:00 2001 From: ryanlath Date: Wed, 6 Mar 2024 11:30:57 -0800 Subject: [PATCH] change exist method to mirror filefs with use of stat() --- loaders/embedfs/loader.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/loaders/embedfs/loader.go b/loaders/embedfs/loader.go index 7b85a5b..d1c443b 100644 --- a/loaders/embedfs/loader.go +++ b/loaders/embedfs/loader.go @@ -3,7 +3,7 @@ package embedfs import ( "embed" "io" - "os" + "io/fs" "path/filepath" "github.com/CloudyKit/jet/v6" @@ -29,6 +29,10 @@ func (l *embedFileSystemLoader) Open(name string) (io.ReadCloser, error) { // Exists implements Loader.Exists() on top of an embed.FS by trying to open the file. func (l *embedFileSystemLoader) Exists(name string) bool { - _, err := l.fs.Open(filepath.Join(l.dir, filepath.FromSlash(name))) - return err == nil && !os.IsNotExist(err) + name = filepath.Join(l.dir, filepath.FromSlash(name)) + stat, err := fs.Stat(l.fs, name) + if err == nil && !stat.IsDir() { + return true + } + return false }