2 goredo -- redo implementation on pure Go
3 Copyright (C) 2020 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)
53 extsOrig := strings.Split(tgt, ".")[1:]
57 updir := path.Join(levels...)
59 doFile = strings.Join(append(
60 []string{"default"}, append(exts, "do")...,
62 pth := path.Join(updir, doFile)
63 exists, err = existsDo(fdDep, cwd, pth)
68 return doFile, len(levels), nil
73 pth := path.Join(updir, doFile)
74 exists, err = existsDo(fdDep, cwd, pth)
79 return pth, len(levels), nil
81 levels = append(levels, "..")
82 dirAbs, err := filepath.Abs(updir)
89 if _, err = os.Stat(path.Join(dirAbs, RedoDir, TopFile)); err == nil {
92 if dirAbs == dirAbsPrev {