/* goredo -- redo implementation on pure Go Copyright (C) 2020 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 the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package main func isOkRun(err error) bool { if err == nil { return true } if err, ok := err.(RunErr); ok && err.Err == nil { trace(CRedo, "%s", err.Name()) return true } trace(CErr, "%s", err) return false } func ifchange(tgts []string) (bool, error) { jsInit() defer jsAcquire("ifchange exiting") defer Jobs.Wait() errs := make(chan error, len(tgts)) jobs := 0 ok := true var err error for _, tgt := range tgts { var ood bool if Force { ood = true } else { ood, err = isOOD(Cwd, tgt, 0) if err != nil { return false, err } } if !ood { continue } if isSrc(Cwd, tgt) { trace(CDebug, "%s is source, not redoing", tgt) continue } if err = runScript(tgt, errs); err != nil { return false, err } if Force { // Sequentially run jobs err = <-errs Jobs.Wait() if isOkRun(err) { continue } return false, nil } jobs++ } for i := 0; i < jobs; i++ { err = <-errs ok = ok && isOkRun(err) } return ok, nil }