2 goredo -- djb's redo implementation on pure Go
3 Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 EnvTopDir = "REDO_TOP_DIR"
35 func existsDo(w io.Writer, fdDepName, cwd, pth string) (bool, error) {
36 if FileExists(path.Join(cwd, pth)) {
39 return false, ifcreate(w, fdDepName, pth)
42 func findDo(w io.Writer, fdDepName, cwd, tgt string) (string, int, error) {
44 exists, err := existsDo(w, fdDepName, cwd, doFile)
53 extsOrig := strings.Split(tgt, ".")[1:]
57 updir := path.Join(levels...)
59 doFile = strings.Join(append(
60 []string{"default"}, append(exts, "do")...,
62 if len(levels) > 0 || (doFile != doFileOrig && doFile != tgt) {
63 exists, err = existsDo(w, fdDepName, cwd, path.Join(updir, doFile))
68 return doFile, len(levels), nil
74 if len(levels) > 0 || (doFile != doFileOrig && doFile != tgt) {
75 exists, err = existsDo(w, fdDepName, cwd, path.Join(updir, doFile))
80 return doFile, len(levels), nil
83 levels = append(levels, "..")
84 dirAbs := mustAbs(path.Join(cwd, updir))
91 if FileExists(path.Join(dirAbs, RedoDir, TopFile)) {
94 if dirAbs == dirAbsPrev {