Skip to content

Commit

Permalink
perf: cache file/dir exists operations
Browse files Browse the repository at this point in the history
  • Loading branch information
gabotechs committed Dec 25, 2023
1 parent 26ac303 commit 21b1ab3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ package utils

import "os"

func FileExists(path string) bool {
func _FileExists(path string) bool {
stat, err := os.Stat(path)
if err != nil {
return false
}
return !stat.IsDir()
}

func DirExists(path string) bool {
var FileExists = Cached(_FileExists)

func _DirExists(path string) bool {
stat, err := os.Stat(path)
if err != nil {
return false
}
return stat.IsDir()
}

var DirExists = Cached(_DirExists)

0 comments on commit 21b1ab3

Please sign in to comment.