1 // goredo -- djb's redo implementation on pure Go
2 // Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 EnvTopDir = "REDO_TOP_DIR"
33 func existsDo(w io.Writer, fdDepName, cwd, pth string) (bool, error) {
34 if FileExists(path.Join(cwd, pth)) {
37 return false, ifcreate(w, fdDepName, pth)
40 func findDo(w io.Writer, fdDepName, cwd, tgt string) (string, int, error) {
42 exists, err := existsDo(w, fdDepName, cwd, doFile)
51 extsOrig := strings.Split(tgt, ".")[1:]
55 updir := path.Join(levels...)
57 doFile = strings.Join(append(
58 []string{"default"}, append(exts, "do")...,
60 if len(levels) > 0 || (doFile != doFileOrig && doFile != tgt) {
61 exists, err = existsDo(w, fdDepName, cwd, path.Join(updir, doFile))
66 return doFile, len(levels), nil
72 if len(levels) > 0 || (doFile != doFileOrig && doFile != tgt) {
73 exists, err = existsDo(w, fdDepName, cwd, path.Join(updir, doFile))
78 return doFile, len(levels), nil
81 levels = append(levels, "..")
82 dirAbs := mustAbs(path.Join(cwd, updir))
89 if FileExists(path.Join(dirAbs, RedoDir, TopFile)) {
92 if dirAbs == dirAbsPrev {