X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=ood.go;h=3ce732f10ec70f6526131b5febeb484a88dc3acb;hb=9aec69aeb699839887d0e7a0d1e7b2f4900e83b0;hp=7a315734287268d3f37c68fe1b82d0a91bc2579e;hpb=992b7b94dd2981b4848ba17317c462e6d875e417;p=goredo.git diff --git a/ood.go b/ood.go index 7a31573..3ce732f 100644 --- 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