2 goredo -- redo implementation on pure Go
3 Copyright (C) 2020-2021 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/>.
30 EnvTopDir = "REDO_TOP_DIR"
36 func existsDo(fdDep *os.File, cwd, pth string) (bool, error) {
37 if _, err := os.Stat(path.Join(cwd, pth)); err == nil {
40 return false, ifcreate(fdDep, pth)
43 func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) {
45 exists, err := existsDo(fdDep, cwd, doFile)
54 extsOrig := strings.Split(tgt, ".")[1:]
58 updir := path.Join(levels...)
60 doFile = strings.Join(append(
61 []string{"default"}, append(exts, "do")...,
63 if len(levels) > 0 || doFile != doFileOrig {
64 exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile))
69 return doFile, len(levels), nil
75 if len(levels) > 0 || doFile != doFileOrig {
76 exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile))
81 return doFile, len(levels), nil
84 levels = append(levels, "..")
85 dirAbs, err := filepath.Abs(updir)
92 if _, err = os.Stat(path.Join(dirAbs, RedoDir, TopFile)); err == nil {
95 if dirAbs == dirAbsPrev {