Skip to content

Commit

Permalink
change exist method to mirror filefs with use of stat()
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanlath authored and sauerbraten committed Mar 7, 2024
1 parent d97443a commit eb1f1c6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions loaders/embedfs/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package embedfs
import (
"embed"
"io"
"os"
"io/fs"
"path/filepath"

"github.com/CloudyKit/jet/v6"
Expand All @@ -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
}

0 comments on commit eb1f1c6

Please sign in to comment.