]> Cypherpunks.ru repositories - goredo.git/blobdiff - ood.go
Cache file existence state
[goredo.git] / ood.go
diff --git a/ood.go b/ood.go
index 7a315734287268d3f37c68fe1b82d0a91bc2579e..3ce732f10ec70f6526131b5febeb484a88dc3acb 100644 (file)
--- a/ood.go
+++ b/ood.go
@@ -47,9 +47,26 @@ var (
        FdOODTgts     *os.File
        FdOODTgtsLock *os.File
 
+       FileExistsCache map[string]bool = make(map[string]bool)
+
        ErrMissingTarget = errors.New("invalid format of .rec: missing Target")
 )
 
+func FileExists(p string) bool {
+       if exists, known := FileExistsCache[p]; known {
+               return exists
+       }
+       _, err := os.Stat(p)
+       if err == nil {
+               FileExistsCache[p] = true
+               return true
+       }
+       if os.IsNotExist(err) {
+               FileExistsCache[p] = false
+       }
+       return false
+}
+
 type TgtError struct {
        Tgt string
        Err error
@@ -80,13 +97,13 @@ func cwdAndTgt(tgt string) (string, string) {
 
 func isSrc(cwd, tgt string) bool {
        d, f := path.Split(path.Join(cwd, tgt))
-       if _, err := os.Stat(path.Join(d, f)); err != nil {
+       if !FileExists(path.Join(d, f)) {
                return false
        }
-       if _, err := os.Stat(path.Join(d, f+".do")); err == nil {
+       if FileExists(path.Join(d, f+".do")) {
                return false
        }
-       if _, err := os.Stat(path.Join(d, RedoDir, f+DepSuffix)); err == nil {
+       if FileExists(path.Join(d, RedoDir, f+DepSuffix)) {
                return false
        }
        return true
@@ -127,14 +144,14 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
                tracef(CDebug, "ood: %s%s -> already built", indent, tgtOrig)
                return false, nil
        }
-       if _, err := os.Stat(path.Join(cwd, tgt)); err != nil && os.IsNotExist(err) {
+       if !FileExists(path.Join(cwd, tgt)) {
                tracef(CDebug, "ood: %s%s -> non-existent", indent, tgtOrig)
                return true, nil
        }
        ood := false
 
        for _, dep := range depInfo.ifcreates {
-               if _, err := os.Stat(path.Join(cwd, dep)); err == nil {
+               if FileExists(path.Join(cwd, dep)) {
                        tracef(CDebug, "ood: %s%s -> %s created", indent, tgtOrig, dep)
                        ood = true
                        goto Done