X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=do.go;h=3312d54f070bd2171afcd955bb2d2d3b19e48bcc;hb=refs%2Fheads%2Fmaster;hp=fd3bde00f75440c902a02d58e239514c00c9f701;hpb=0030b3e73152bf9d9ad3e435fa42e607c7865321;p=goredo.git diff --git a/do.go b/do.go index fd3bde0..3312d54 100644 --- a/do.go +++ b/do.go @@ -1,28 +1,25 @@ -/* -goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2022 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 -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 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 +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . // .do finder package main import ( - "os" + "io" "path" - "path/filepath" "strings" ) @@ -33,16 +30,16 @@ const ( var TopDir string -func existsDo(fdDep *os.File, cwd, pth string) (bool, error) { - if _, err := os.Stat(path.Join(cwd, pth)); err == nil { +func existsDo(w io.Writer, fdDepName, cwd, pth string) (bool, error) { + if FileExists(path.Join(cwd, pth)) { return true, nil } - return false, ifcreate(fdDep, pth) + return false, ifcreate(w, fdDepName, pth) } -func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { +func findDo(w io.Writer, fdDepName, cwd, tgt string) (string, int, error) { doFile := tgt + ".do" - exists, err := existsDo(fdDep, cwd, doFile) + exists, err := existsDo(w, fdDepName, cwd, doFile) if err != nil { return "", 0, err } @@ -61,7 +58,7 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { []string{"default"}, append(exts, "do")..., ), ".") if len(levels) > 0 || (doFile != doFileOrig && doFile != tgt) { - exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) + exists, err = existsDo(w, fdDepName, cwd, path.Join(updir, doFile)) if err != nil { return "", 0, err } @@ -73,7 +70,7 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { } doFile = "default.do" if len(levels) > 0 || (doFile != doFileOrig && doFile != tgt) { - exists, err = existsDo(fdDep, cwd, path.Join(updir, doFile)) + exists, err = existsDo(w, fdDepName, cwd, path.Join(updir, doFile)) if err != nil { return "", 0, err } @@ -82,14 +79,14 @@ func findDo(fdDep *os.File, cwd, tgt string) (string, int, error) { } } levels = append(levels, "..") - dirAbs, err := filepath.Abs(path.Join(cwd, updir)) + dirAbs := mustAbs(path.Join(cwd, updir)) if err != nil { panic(err) } if dirAbs == TopDir { break } - if _, err = os.Stat(path.Join(dirAbs, RedoDir, TopFile)); err == nil { + if FileExists(path.Join(dirAbs, RedoDir, TopFile)) { break } if dirAbs == dirAbsPrev {