X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=do.go;h=516b1438c28d5751d477f645c57c45aae47f0956;hb=eb14a3333a632b22a4b698ca28fea6e6d11048b8;hp=e120680fa05599c80b8c0dcc3d8ffc844886a2e8;hpb=634ee31ae35a2eaac517e0ffa1b7caede4b27ac5;p=goredo.git diff --git a/do.go b/do.go index e120680..516b143 100644 --- a/do.go +++ b/do.go @@ -1,6 +1,6 @@ /* -goredo -- redo implementation on pure Go -Copyright (C) 2020 Sergey Matveev +goredo -- djb's redo implementation on pure Go +Copyright (C) 2020-2021 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 @@ -49,6 +49,7 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { if exists { return doFile, 0, nil } + doFileOrig := doFile levels := []string{} extsOrig := strings.Split(tgt, ".")[1:] dirAbsPrev := "" @@ -59,27 +60,29 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { doFile = strings.Join(append( []string{"default"}, append(exts, "do")..., ), ".") - pth := path.Join(updir, doFile) - exists, err = existsDo(fdDep, cwd, pth) + if len(levels) > 0 || doFile != doFileOrig { + exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) + if err != nil { + return "", 0, err + } + if exists { + return doFile, len(levels), nil + } + } + exts = exts[1:] + } + doFile = "default.do" + if len(levels) > 0 || doFile != doFileOrig { + exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) if err != nil { return "", 0, err } if exists { return doFile, len(levels), nil } - exts = exts[1:] - } - doFile = "default.do" - pth := path.Join(updir, doFile) - exists, err = existsDo(fdDep, cwd, pth) - if err != nil { - return "", 0, err - } - if exists { - return pth, len(levels), nil } levels = append(levels, "..") - dirAbs, err := filepath.Abs(updir) + dirAbs, err := filepath.Abs(path.Join(cwd, updir)) if err != nil { panic(err) }