]> Cypherpunks.ru repositories - goredo.git/blobdiff - ood.go
Cache OOD decisions
[goredo.git] / ood.go
diff --git a/ood.go b/ood.go
index 3ce732f10ec70f6526131b5febeb484a88dc3acb..6e9043cc0762e0962a8c28df2c82d9238a56f5fb 100644 (file)
--- a/ood.go
+++ b/ood.go
@@ -47,6 +47,7 @@ var (
        FdOODTgts     *os.File
        FdOODTgtsLock *os.File
 
+       OODCache        map[string]bool = make(map[string]bool)
        FileExistsCache map[string]bool = make(map[string]bool)
 
        ErrMissingTarget = errors.New("invalid format of .rec: missing Target")
@@ -128,10 +129,16 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
        indent := strings.Repeat(". ", level)
        tracef(CDebug, "ood: %s%s checking", indent, tgtOrig)
        cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig))
+       ood, cached := OODCache[path.Join(cwd, tgt)]
+       if cached {
+               tracef(CDebug, "ood: %s%s -> cached: %v", indent, tgtOrig, ood)
+               return ood, nil
+       }
        depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
        fdDep, err := os.Open(depPath)
        if err != nil {
                tracef(CDebug, "ood: %s%s -> no dep: %s", indent, tgtOrig, depPath)
+               OODCache[path.Join(cwd, tgt)] = true
                return true, nil
        }
        depInfo, err := depRead(fdDep)
@@ -142,13 +149,14 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
 
        if depInfo.build == BuildUUID {
                tracef(CDebug, "ood: %s%s -> already built", indent, tgtOrig)
+               OODCache[path.Join(cwd, tgt)] = false
                return false, nil
        }
        if !FileExists(path.Join(cwd, tgt)) {
                tracef(CDebug, "ood: %s%s -> non-existent", indent, tgtOrig)
+               OODCache[path.Join(cwd, tgt)] = true
                return true, nil
        }
-       ood := false
 
        for _, dep := range depInfo.ifcreates {
                if FileExists(path.Join(cwd, dep)) {
@@ -169,12 +177,21 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
                }
                theirHsh := m["Hash"]
                tracef(CDebug, "ood: %s%s -> %s: checking", indent, tgtOrig, dep)
+               ood, cached = OODCache[path.Join(cwd, dep)]
+               if cached {
+                       tracef(CDebug, "ood: %s%s -> %s: cached: %v", indent, tgtOrig, dep, ood)
+                       if ood {
+                               goto Done
+                       }
+                       continue
+               }
 
                inode, err := inodeFromFileByPath(path.Join(cwd, dep))
                if err != nil {
                        if os.IsNotExist(err) {
                                tracef(CDebug, "ood: %s%s -> %s: not exists", indent, tgtOrig, dep)
                                ood = true
+                               OODCache[path.Join(cwd, dep)] = ood
                                goto Done
                        }
                        return ood, TgtError{tgtOrig, err}
@@ -183,6 +200,7 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
                if inode.Size != theirInode.Size {
                        tracef(CDebug, "ood: %s%s -> %s: size differs", indent, tgtOrig, dep)
                        ood = true
+                       OODCache[path.Join(cwd, dep)] = ood
                        goto Done
                }
                if InodeTrust != InodeTrustNone && inode.Equals(theirInode) {
@@ -201,6 +219,7 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
                        if theirHsh != hsh {
                                tracef(CDebug, "ood: %s%s -> %s: hash differs", indent, tgtOrig, dep)
                                ood = true
+                               OODCache[path.Join(cwd, dep)] = ood
                                goto Done
                        }
                        tracef(CDebug, "ood: %s%s -> %s: same hash", indent, tgtOrig, dep)
@@ -212,11 +231,13 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
                }
                if isSrc(cwd, dep) {
                        tracef(CDebug, "ood: %s%s -> %s: is source", indent, tgtOrig, dep)
+                       OODCache[path.Join(cwd, dep)] = false
                        continue
                }
 
                if _, ok := seen[cwdMustRel(cwd, dep)]; ok {
                        tracef(CDebug, "ood: %s%s -> %s: was always built", indent, tgtOrig, dep)
+                       OODCache[path.Join(cwd, dep)] = false
                        continue
                }
 
@@ -234,6 +255,7 @@ func isOOD(cwd, tgtOrig string, level int, seen map[string]struct{}) (bool, erro
 
 Done:
        tracef(CDebug, "ood: %s%s: %v", indent, tgtOrig, ood)
+       OODCache[path.Join(cwd, tgt)] = ood
        return ood, nil
 }