X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=run.go;h=a3740c25a83d9c8e7576e4856b974d76368526c2;hb=0030b3e73152bf9d9ad3e435fa42e607c7865321;hp=ea14641a9304bd85adbee7c988cebdcc3059242c;hpb=d8abe40c66df8d79a025524c0d230959cacf9465;p=goredo.git diff --git a/run.go b/run.go index ea14641..a3740c2 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,6 @@ /* goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2021 Sergey Matveev +Copyright (C) 2020-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -322,7 +322,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { runErr.DoFile = doFileRelPath } - if err = writeDep(fdDep, cwdOrig, doFileRelPath); err != nil { + if err = depWrite(fdDep, cwdOrig, doFileRelPath); err != nil { cleanup() return TgtError{tgtOrig, err} } @@ -616,10 +616,9 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { // Was $1 touched? if fd, err := os.Open(path.Join(cwdOrig, tgt)); err == nil { - errTouched := Err1WasTouched if inodePrev == nil { fd.Close() - runErr.Err = errTouched + runErr.Err = Err1WasTouched errs <- runErr return } @@ -631,7 +630,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { return } if !inode.Equals(inodePrev) { - runErr.Err = errTouched + runErr.Err = Err1WasTouched errs <- runErr return } @@ -683,7 +682,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { fd = fdStdout } - // Do we need to ifcreate it, of ifchange with renaming? + // Do we need to ifcreate it, or ifchange with renaming? if fd == nil { os.Remove(path.Join(cwdOrig, tgt)) err = ifcreate(fdDep, tgt) @@ -707,7 +706,7 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { goto Finish } } - err = writeDep(fdDep, cwdOrig, tgt) + err = depWrite(fdDep, cwdOrig, tgt) if err != nil { goto Finish } @@ -731,6 +730,26 @@ func runScript(tgtOrig string, errs chan error, traced bool) error { goto Finish } } + + // Post-commit .rec sanitizing + fdDep.Close() + if fdDepR, err := os.Open(fdDepPath); err == nil { + depInfo, err := depRead(fdDepR) + fdDepR.Close() + if err != nil { + goto Finish + } + ifchangeSeen := make(map[string]struct{}, len(depInfo.ifchanges)) + for _, dep := range depInfo.ifchanges { + ifchangeSeen[dep["Target"]] = struct{}{} + } + for _, dep := range depInfo.ifcreates { + if _, exists := ifchangeSeen[dep]; exists { + tracef(CWarn, "simultaneous ifcreate and ifchange records: %s", tgt) + } + } + } + Finish: runErr.Err = err errs <- runErr